0 votes
by (120 points)
I have an array with. e.g. ten variables, how do I take three random of them without them repeating?

2 Answers

0 votes
by (6.2k points)

Try the (move:) macro? I'm sorry, I don't really use arrays much, but if you're only using them to store random events I suggest you use the (either:) macro instead.

(either: '(set: $random to 1)','(set: $random to 2)','(set: $random to 3)')

Sorry if this isn't helpful.

+1 vote
by (159k points)

I have an array with. e.g. ten variables...

The items contained within an array are generally called either elements or values.

You can use the (shuffled:) macro to randomly sort the elements of an array like so..

(set: $array to (a: "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"))

(set: $shuffled to (shuffled: ...$array))

original array: (print: $array)
shuffled array: (print: $shuffled)

So if you want three random values from an array you could do something like the following:

(set: _shuffled to (shuffled: ...(a: "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten")))

(set: _first to $shuffled's 1st)
(set: _second to $shuffled's 2nd)
(set: _third to $shuffled's 3rd)

1st: _first
2nd: _second
3rd: _third

 

...