Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

RE: RE: RE: Randomizing Unique ID?

by Adam (Vicar)
on Aug 09, 2000 at 22:03 UTC ( #27127=note: print w/ replies, xml ) Need Help??

in reply to RE: RE: Randomizing Unique ID?
in thread Randomizing Unique ID?

Well, If you want more room in the double, then do the base conversion before doing the concatenation, thusly:

# Generate a truly unique ID sub GenerateBase { my $base = shift; $base = 62 if $base > 62; my @nums = (0..9,'a'..'z','A'..'Z')[0..$base-1]; return sub { my $number = shift; my $rep = ""; # this will be the end value. while( $number > 0 ) { $rep = $nums[$number % $base] . $rep; $number = int( $number / $base ); } return $rep; } } my $ToBase62 = GenerateBase( 62 ); my $ID = $ToBase62->( $$ ) . $ToBase62->( time );

Comment on RE: RE: RE: Randomizing Unique ID?
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://27127]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2015-10-10 20:19 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (258 votes), past polls