Holiday notice: Cycling '74 will be closed Monday, October 9th. Manual authorization, support cases, and manual order processing will be delayed.

Apr 18 2013 | 7:45 pm

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

is this correct?

thanks

Arun

- Apr 18 2013 | 8:10 pmThat is correct.
- Apr 18 2013 | 8:46 pmBTW, The sadam Library (see https://cycling74.com/forums/announce-the-sadam-library-version-2012-10-08 ) 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
- Apr 19 2013 | 9:53 amNo 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):
- Apr 20 2013 | 8:27 pmisnt it interesting, that the highest possible random number can be foreseen exactly. one would exspect that it is randomly changing over time.
- Apr 21 2013 | 11:18 amAll 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).
- Apr 21 2013 | 12:57 pmtrue 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.
- Apr 21 2013 | 2:04 pmNo, 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)
- Apr 21 2013 | 4:24 pmauch nicht schlecht.
- Apr 22 2013 | 2:25 amThere are many algorithms for random number generators. What algorithm does Max use?
- Apr 22 2013 | 8:27 amDavid 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.