Choose always chooses last parameter

I just downloaded Sonic Pi yesterday so please excuse if this is a dumb question.
Running 3.2 on Windows 10
Choose seems to always select the last option e.g.

play choose([50, 55, 62])

will always platy 62 …… am I missing a randomize or something beforehand
TIA

Hi @RamblinLane,

welcome to our forums! Thanks for asking this question - it’s not dumb at all. If you don’t know what’s going on inside Sonic Pi, then this behaviour can be quite strange when first met.

Essentially Sonic Pi’s randomisation is not random. This is by design. It means that the code you write will always produce the same music - even if it includes randomisation. I think it’s way more useful to be able to email your code to someone else and know what they’re going to hear, or to run an older bit of code and have it sound the same now as it did. It also means you can look at other people’s code and copy bits and replicate it easily.

If you try the following you’ll see that it is random within a given program:

8.times do
  play choose([50, 55, 62]), release: 0.1
  sleep 0.125
end

You’ll hear 8 random choices. However, if you run the code again, you’ll hear the same 8 random choices, so again the same code will always produce the same sounds.

This is called deterministic randomisation. For more information please do take a look at Section 4 of our built-in tutorial https://sonic-pi.net/tutorial.html#section-4

1 Like

Thank you samaaron
Will look at that section 4
Sonic Pi is really cool

1 Like