return truely random number?

S

sam

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
 
A

ajs

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

sam

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

Joe Smith

sam said:
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";
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,439
Latest member
shasuze

Latest Threads

Top