Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: Get your Bumpers ready!



Hi Craig,

On 18-Nov-97 Craig Oda wrote:
>> # enter that number into an array
>> @example.com=(0..$cooldudes);
>> 
>> #get a whole number from @example.com 
>> $win = int(rand@example.com) +1 ;
>this looks good.  I'm wondering how Perl specifies the range.

The range should be set by the contents of the array @example.com

>If the random number is out of range, does it do a recalculation
>of the random number?  

In this case, Perl isn't being asked to generate a 'random' number but
is being instructed to randomly select an element from the array based on a
random number generator.  

>Also, what does it use for the salt,
>the system clock?  

The salt is generated via the clock and the rand() operator.

>From the Nutshell Camel book:

--------------------------------
srand EXPR

This function sets the random number seed for the rand operator. If EXPR is
omitted, it does srand(time), which is pretty predictable, so don't use it for
security type things, such as random password generation.
--------------------------------

The authors suggest using:

srand( time() ^ ($$ + ($$ << 15)) );

There's also a Math::TrulyRandom module on CPAN, but I've never messed with it.
I've used rand() a couple of times on web pages where I wanted to get a
randomly selected image to load.

Blaine's comment that setting the array means that 'true' randomness is
unachievable is correct. Basically, I was playing with the assumption that
'pulling a name out of a hat' was the goal.

>Ahh, to use hitech or lotech that is the question.  Which is
>more random?

Use whatever is the most fun....
---------------------------------------------------------------
TLUG Meeting Dec. 13, 12:30 at Tokyo station Yaesu Chuo ticket gate
13:30 Starbuck's coffee.  13:45 HSBC | info: joem@example.com
At least 3 functional Sparc IPC machines will be raffled out
---------------------------------------------------------------
a word from the sponsor:
TWICS - Japan's First Public-Access Internet System
www.twics.com  info@example.com  Tel:03-3351-5977  Fax:03-3353-6096



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links