Choosing a Number Randomly From a Predefined List

Hi all, Chris here. I got a quick question which hopefully as a simple solution. =

The premise is, I want a variable, n let’s say, to be equal to a random number, but there are only certain numbers that I want it to be allowed to equal. I’ve designated these numbers in a list I’ve named Scale Value. I’ve exhausted the manuals and index in every possible way I know how and I have yet to find a solution to my problem. The compiler simply fails to recognize I’m trying to get n equal to one of the numbers in the list Scale Value. I’ve come to believe this is possible due to a different topic I read where someone offered a similar solution to a slightly different problem.

To make things clearer, here is the code (probably clumsy… still learning) that I have come up with so far:

Scale Value is a list of numbers that varies.
Scale Value is { 4, 6, 10, 8, 12, 14 }

n is a number that varies… When play begins: [set n to a random number available in scale value???]

Any help is appreciated.
Thanks,
Chris

You could do something like this:

When play begins: let r be a random number from 1 to the number of entries in Scale Value; now n is entry r of Scale Value.

Bless your heart, it worked! Thanks. I have agonized over this for days.

Much appreciated!

I don’t know if your code was just an example or the actual code, but if the values follow that pattern (even numbers between 4 and 14) you don’t need the list, you can pick a number using a formula:

When play begins:
    let n be (a random number between 2 and 7) times 2.

Oh yes, that is much more concise. Thanks a lot, I think I’ll do it that way. Feel a little dumb my brain didn’t make that connection myself.

Thanks!

===after trying===
Hmm… Perhaps it’s my own incompetence, but when entering your code how you provided it n always winds up being equal to 0.

“Let” is for a temporary variable. If you want to be able to refer to n elsewhere, you can say

now n is

instead of

let n be

so, like this:

When play begins: now n is (a random number between 2 and 7) times 2.