Bignum + rand()

Is there a portable way to find out the biggest number I can pass to
rand() that doesn’t result in the following exception?

in `rand'(TestRMailHeader): bignum too big to convert
into `int' (RangeError)

Hi,

···

In message “Bignum + rand()” on 03/01/26, Matt Armstrong matt@lickey.com writes:

Is there a portable way to find out the biggest number I can pass to
rand() that doesn’t result in the following exception?

in rand'(TestRMailHeader): bignum too big to convert into int’ (RangeError)

rand() should work for any numbers. Could you tell me more info to
reproduce the exception?

						matz.

rand() should work for any numbers. Could you tell me more info to
reproduce the exception?

pigeon% ./ruby -ve 'p rand(9999999999999999999999999)'
ruby 1.8.0 (2003-01-20) [i686-linux]
-e:1:in `rand': bignum too big to convert into `int' (RangeError)
        from -e:1
pigeon%

rb_f_rand() has only the case T_FLOAT, T_NIL and default (NUM2LONG give
the error)

Guy Decoux

Hi,

···

In message “Re: Bignum + rand()” on 03/01/26, ts decoux@moulon.inra.fr writes:

rand() should work for any numbers. Could you tell me more info to
reproduce the exception?

pigeon% ./ruby -ve ‘p rand(9999999999999999999999999)’
ruby 1.8.0 (2003-01-20) [i686-linux]
-e:1:in rand': bignum too big to convert into int’ (RangeError)
from -e:1
pigeon%

rb_f_rand() has only the case T_FLOAT, T_NIL and default (NUM2LONG give
the error)

Oops, I somehow removed T_BIGNUM code from 1.8.0, I will fix.

						matz.