Some objects for generating numbers

This patch shows four objects that are useful for generating numbers, each with a different behavior. The arguments to these objects determine how many different possible numbers the object will generate, and the range of those numbers. The range can be changed, though, by scaling (multiplying) them and/or by offsetting (adding something to) them.

Random and urn

This patch demonstrates the two simplest objects for generating random numbers. Every time it receives a bang in its left inlet, the random object generates a random integer in the range from 0 to one less than its argument. (For example, if you tell it to generate one of 12 random numbers, it will choose a number from 0 through 11 inclusive.) Note that this includes the possibility that successive random choices may appear to generate what seem to be patterns, especially if it's choosing from among a small range of possibilities.

Random numbers without repetitions

The random object outputs a pseudo-randomly chosen integer. The range of possible numbers is determined by the number received in the right inlet (or specified as a typed-in argument). Each time random receives a bang, it will output one of n possible numbers, ranging from 0 to n-1. Because each number has an equal probability of occurring each time, there’s a possibility that repetitions will occur. If you wish to prevent repetitions there are two approaches.