Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > return truely random number?

Reply
Thread Tools

return truely random number?

 
 
sam
Guest
Posts: n/a
 
      12-23-2004
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
 
Reply With Quote
 
 
 
 
ajs@ajs.com
Guest
Posts: n/a
 
      12-23-2004
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.

 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      12-24-2004
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

 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      12-25-2004
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";
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
How to verify if an employee truely has an MCSE =?Utf-8?B?Qm9kaW5lOTU=?= Microsoft Certification 8 01-15-2010 06:52 AM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
what the java virtual machine truely is? 525 Java 5 03-08-2008 03:27 AM
At least we truely now know who to ultimately blame for the prolonged HDDVD/blu ray war! GMAN DVD Video 3 02-26-2008 07:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57