largest number for random

Apr 18, 2013 at 7:45pm

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

#67805
Apr 18, 2013 at 8:10pm

That is correct.

#243795
Apr 18, 2013 at 8:46pm

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

#243796
Apr 19, 2013 at 9:53am

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. –
#243797
Apr 20, 2013 at 8:27pm

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

#243798
Apr 21, 2013 at 11:18am

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).

#243799
Apr 21, 2013 at 12:57pm

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.

#243800
Apr 21, 2013 at 2:04pm

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)

#243801
Apr 21, 2013 at 4:24pm

auch nicht schlecht.

#243802
Apr 22, 2013 at 2:25am

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

#243803
Apr 22, 2013 at 8:27am

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.

#243804

You must be logged in to reply to this topic.