Difference between revisions of "Shuffle"
Line 4: | Line 4: | ||
[[What's new in Analytica 4.0?]] > | [[What's new in Analytica 4.0?]] > | ||
− | = Function Shuffle(a | + | = Function Shuffle(a '', i'') = |
− | Shuffle returns a random reordering (permutation) of the values in array a over index i. If you omit i, it shuffles over Run. [Since build 4.0.0.48.] You can use it generate an independent random sample from an existing probability distribution, a. | + | Shuffle returns a random reordering (permutation) of the values in array a over index i. If you omit i, it shuffles over [[Run]]. [Since build 4.0.0.48.] You can use it generate an independent random sample from an existing probability distribution, a. |
− | = | + | = Independent Shuffles = |
− | + | If ''a'' contains extra dimensions, or if you include the Over parameter, e.g.: | |
+ | :Shuffle(a,I,Over:J) | ||
+ | then the elements are shuffled independently over those extra dimensions. | ||
If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method: | If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method: | ||
Line 17: | Line 19: | ||
This shuffles A over index I, but does not shuffle each slice of A for each value of I. | This shuffles A over index I, but does not shuffle each slice of A for each value of I. | ||
+ | |||
+ | = Examples = | ||
+ | |||
+ | To generate a random permutation of the numbers 1..100: | ||
+ | |||
+ | Index I:=1..100 do Shuffle(I,I) |
Revision as of 23:48, 6 March 2008
What's new in Analytica 4.0? >
Function Shuffle(a , i)
Shuffle returns a random reordering (permutation) of the values in array a over index i. If you omit i, it shuffles over Run. [Since build 4.0.0.48.] You can use it generate an independent random sample from an existing probability distribution, a.
Independent Shuffles
If a contains extra dimensions, or if you include the Over parameter, e.g.:
- Shuffle(a,I,Over:J)
then the elements are shuffled independently over those extra dimensions.
If you want to shuffle the slices of a multidimensional array over index i, without shuffling the values within each slice, use this method:
A[@I = Shuffle(@I,I)]
This shuffles A over index I, but does not shuffle each slice of A for each value of I.
Examples
To generate a random permutation of the numbers 1..100:
Index I:=1..100 do Shuffle(I,I)
Comments
Enable comment auto-refresher