Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello all, I am making a script that requires large random ints. In my script I have loaded Math::BigInt, but I can't get rand() to return a value that isn't in x.xxxxxxxe+XXX form (i.e. 3.86048394e+038).
I want to look like this for example 3860483945856454234548484.
What can I do to get a large random number? Thanks. Bye

Replies are listed 'Best First'.
Re: Big ints and random ints
by Masem (Monsignor) on Jan 31, 2002 at 14:54 UTC
    Generate the random number by sticking together N random digits to get. For example, if you want a random number between 1e30 and 9.99e39:
    my $num = join '', map { int rand 10 } (0..(30 + int rand 10) );
    Update actually, you don't even need the rand at the end; to go from 0 to 9.99e39:
    my $num = join '', map { int rand 10 } (0..39);
    as numbers of 38 digits or less will have zeroes prepended to them.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important