First time here? Check out the FAQ!

how to generate a limited series of random numbers

0 votes
hello everybody,

I would like to generate a series of seeded random numbers that is not infinite but that repeat itself, for example every 64 beats.

how can I do it?


asked Nov 11, 2016 in Capytalk & Smalltalk by domenico-cipriani (Master) (3,110 points)

1 Answer

0 votes
Best answer

Perhaps you could generate an Array of random numbers and then use the of: message to repeatedly read from that Array?  For example, something like this:

| r |

r := Random newForKymaWithSeed: 879.

(1 s tick nextIndexMod: 64) of: (1 to: 64 collect: [:i | r next])

If you'd like to be able to change the contents of the Array, you could instead use something more like the following, in which case you could use !Trigger each time you'd like to generate a new set of 64 random values:

(0.2 s tick nextIndexMod: 64) of: (1 to: 64 collect: [:i | !Trigger nextRandom * 36 nn + 48 nn])

answered Nov 11, 2016 by ssc (Savant) (121,880 points)
selected Nov 11, 2016 by domenico-cipriani
thanks a lot! this is working for me.
but what if I want to have a Seed that is an hotvalue?
Modified the original answer to address this question (please see above). Thanks!