### largest number for random

by trial and error, I’ve found that the largest number returned by random is 2**31 – 1. (2147483647)

is this correct?

thanks

Arun

That is correct.

BTW, The sadam Library (see http://cycling74.com/forums/topic.php?id=42930 ) contains an object (`[sadam.limits]`

) which will tell you the largest and smallest float and integer that can be represented by Max on different platforms.

HTH,

Ádám

No real need for trial-and-error. Max uses 32-bit integers and 32-bit floating point. Integers are in 2s-complement, so the largest value that can be represented is (2^31)-1. This holds for [random], [counter], [number], etc. etc. and for every other object dealing with ints. And this is true for both Mac OS and Windows (always has been).

The only exception is Max 6.1 in 64-bit mode, and here a bit of trial-and-error may prove interesting. As I understand the SDK, Max uses 64-bit atoms (ie, 64-bit ints, floats, pointers, etc.) But that doesn’t necessarily mean that absolutely all objects will automatically be working with 64-bit structures internally. In particular, the algorithm for [random] that DDZ documented here many years ago is intrinsically 32-bit (note: the algorithm would easily handle unsigned 32-bit ints, but Max interprets all ints as signed). It would be necessary to modify the calculations performed inside [random] to generate values outside the 32-bit range.

A quick look seems to indicate that, in Max 6.1 under 64-bit mode, it is possible to feed [random] a range parameter larger than (2^31)-1. However, it’s not immediately clear what this is doing! Take a look (don’t forget to set Max 6.1 to 64-bit mode, what happens in 32-bit mode is perfectly clear and a little bit boring):

-- Pasted Max Patch, click to expand. --Copyallof the following text. Then, in Max, selectNew From Clipboard.----------begin_max5_patcher---------- 376.3ocoSsraCBCD7L7UXsmoUXmDTUu0uippHC3l3HvFYLozFk+8ZuFxqRZi R4.V630yN6306hifbcunEHOSdkDEsKNJBg7.QCwQPMuunh2hoApt5bgARBa4 hjpJgE2iN.9tVYakeIPL1ioCvMbawZoZ0RinvFJIcwL21DJMyuvXLbI8wTxa mvkhWibAuXj7pwRq6rtBa+rQD3BjJKjPfbtZEb37xR7j57MOLGNvoolaOUwM biqFVgYoPwyqPFSO1hgRg8HyCtON1+K4Fsr7NqUq9UK65dCawnmbgy7i9+pM 9LXxVgdGshR7giwQ9rhdTrfgqJ00jEoG9lraY26.RFZBT1S+24iorG5eaO3w fJo5x2Jnj83m6Ys5NSwXcGpA4nnKEsVohaktohi4L+rbVKKKEpSGDKks9YST 3oSd2cqpY1MnF5cplfUwaZ1JLsCThBwMHsQa7gYIXnTEBw2.fQrUNle.gabS CV2nPmIb81mMGh80Ye72YLJFQC -----------end_max5_patcher-----------

isnt it interesting, that the highest possible random number can be foreseen exactly. one would exspect that it is randomly changing over time.

All random number generators have some parameters. Range is only the most common (after distribution, which is also more-or-less constant for [random]).

The thing with [random 2147483647] is that you’re going to have to wait an awfully long time the highest value to come out (which, btw, is 2147483646… one less than the range). And just how long you’re going to have to wait is unpredictable (or, at least, very difficult to foresee).

true randomness would be when you ask a computer to perform [random 5] – and 1300 years earlier no apple pie were baked in an airplane tunnel.

No, that’s the punchline to "how many surrealists does it take to change a lightbulb?"

True randomness is when the most compact way to describe a sequence is the sequence itself. (Martin Gardner, Mathematical Carnival, 1977)

auch nicht schlecht.

There are many algorithms for random number generators. What algorithm does Max use?

David Zicarelli posted that [random] simply used the Linear Congruence algorithm as implemented in Numerical Recipes. This was many years ago, but there is no particular reason why this should have changed (although, as mentioned earlier, the 64-bit environment might be a motivation to update).

Yes, the Numerical Recipes implementation is a weak RNC (deterministic low-order bits, correlations in higher dimensions) but it is apparently deemed "good enough" for use in Max/MSP.

In case you don’t know this, there are much stronger RNCs implemented in the Litter Power Package, as well as pretty much every random number distribution known to humankind.

Forums > MaxMSP