return truely random number?

Discussion in 'Perl Misc' started by sam, Dec 23, 2004.

  1. sam

    sam Guest

    Hi,

    I tried Math::Random and Math::Random::MT, but none of them can generate
    turely random number when I executed the following code in a short time
    frame (twice in a second):

    #!/usr/bin/perl

    #use Math::Random;
    use Math::Random::MT;

    $gen = Math::Random::MT->new($seed); # OR... $gen =
    Math::Random::MT->new(@seed);

    print $gen->rand(3)."\n";

    #$random = random_uniform();
    #$gmt = gmtime();

    #print "Random: " . $random . "-" . $gmt . "\n";

    I m trying to generate a transaction code for a data base table using
    the format of random-GMT

    Another question is how can I generate a gmt time in the format 92783456
    instead of "Thu Dec 23 15:02:08 2004"?

    Thanks
    Sam
    sam, Dec 23, 2004
    #1
    1. Advertising

  2. sam

    Guest

    Other posts point out the flaw in your code, but you might also want to
    look at Math::TrulyRandom, which I like and use often.
    , Dec 23, 2004
    #2
    1. Advertising

  3. sam

    sam Guest

    Just found one, Crypt::Random depend on /dev/random device, it really
    does give random number no matter how fast I generate the number...

    Sam.

    sam wrote:
    > Hi,
    >
    > I tried Math::Random and Math::Random::MT, but none of them can generate
    > turely random number when I executed the following code in a short time
    > frame (twice in a second):
    >
    > #!/usr/bin/perl
    >
    > #use Math::Random;
    > use Math::Random::MT;
    >
    > $gen = Math::Random::MT->new($seed); # OR... $gen =
    > Math::Random::MT->new(@seed);
    >
    > print $gen->rand(3)."\n";
    >
    > #$random = random_uniform();
    > #$gmt = gmtime();
    >
    > #print "Random: " . $random . "-" . $gmt . "\n";
    >
    > I m trying to generate a transaction code for a data base table using
    > the format of random-GMT
    >
    > Another question is how can I generate a gmt time in the format 92783456
    > instead of "Thu Dec 23 15:02:08 2004"?
    >
    > Thanks
    > Sam
    sam, Dec 24, 2004
    #3
  4. sam

    Joe Smith Guest

    sam wrote:

    > Another question is how can I generate a gmt time in the format 92783456
    > instead of "Thu Dec 23 15:02:08 2004"?


    Familiarize yourself with the arguments to gmtime and its return value.

    $seconds_since_the_epoch = time;
    @time_array = gmtime($seconds_since_the_epoch);
    $time_scalar = gmtime($seconds_since_the_epoch);
    print "time=$seconds_since_the_epoch time_array=(@time_array)
    time_scalar='$time_scalar'\n";
    Joe Smith, Dec 25, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xeys_00
    Replies:
    12
    Views:
    852
    Jonathan Arnold
    Apr 11, 2005
  2. 525
    Replies:
    5
    Views:
    328
    Arne Vajhøj
    Mar 8, 2008
  3. globalrev
    Replies:
    4
    Views:
    756
    Gabriel Genellina
    Apr 20, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    658
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,158
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page