Gaz Wilson wrote:
> Hi all!
> 
> I am having a very odd problem, which has been going on for ages:
> 
> Many many months ago, I wrote a small program to generate a random
> number based on the number of files in a directory, the aim of the
> program is basically a random background generator - all was working
> fine, until I installed openssh on the machine, and the entropy
> daemon that comes with it.  Ever since then, perl is unable to
> generate random numbers.  There are 40 files in my pictures
> directory, so my program picks a number between 1 and 40, the result
> is ALWAYS 29.  If I write a small program to simply pick a number
> between 1 and 9999, the result is ALWAYS 9575.
> 
> This was using Solaris8 and it's standard Perl (old version), but
> today I installed 5.8.0 as a precompiled package, with the same
> result, I then removed this and built 5.8.0 from source, with the
> same result (although during the test phase, 1 test failed -
> op/srand.t - but it didn't way why - just the line number it failed
> on (which is the last line)) 

This is HIGHLY suspicious. You need to pursue this further.

> 
> Has anyone seen this odd behaviour before?
> 
> Below is a code chunk which should work (and used to) but no longer
> does: 
> 
> #!/usr/local/bin/perl
> @list = `ls /u/gwilson/backdrops/1280x1024`;
> $num = @list;
> srand;
> $randnum = int(rand($num));
> print "num is: $num, randnum is: $randnum\n";
> print "\n\nand now a pure random number with no limits (well,
> 9999)\n"; $rrr = int(rand(9999));
> print "rrr: $rrr\n\n";
> 
> $num always gets set to 40 (number of files in the directory)
> - the output
> from this program is:
> 
> $ ./randnum.pl
> num is: 40, randnum is: 29
> 
> 
> and now a pure random number with no limits (well, 9999) rrr: 9575
> 
> Repeatedly running the script returns the same values every time...

This code produces different output for me each time it's run.

If you pass different values to srand, do you get different results? Try
using srand(time) for instance.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to