1. Random
Useful tips about the random function in Extempore.
1.1 Background
Apparently Standard Scheme does not provide a random number generator. But no worries, there are multiple ways to achieve that as discussed in this SO thread.
Luckily Extempore comes with its own implementation of random. However, the original Extempore version always returns an integer when arguments are provided.
That's not exactly what I wanted as in some situation I'd like to get a random float from any two numbers. So I made a version that does that:
I've updated it on lines 11-12, so that if the first argument it's a float, then it returns a float.
1.2 Random float
Generates a float from 0 to 1.
1.3 Random from list
Returns a random element from the list.
Heads up: symbols are evaluated before being returned!
1.4 Random with boundaries
Returns a random integer from 2 to 5 (excluded).
Returns a random floating number from 2 to 5 (excluded).
Defaults
The second element is always 0, hence this returns a random integer from 0 to 2 (excluded).
The second element is always 0, hence this returns a random float from 0 to 2 (excluded).