Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool.mu.edu!uwm.edu!bionet!agate!ucbvax!ucdavis!csusac!sactoh0!tree!asmodeus From: asmodeus@tree.uucp (Jon Ballard) Newsgroups: comp.lang.perl Subject: Re: random numbers? Message-ID: <1991Feb16.034603.27439@tree.uucp> Date: 16 Feb 91 03:46:03 GMT References: <16698@venera.isi.edu> Reply-To: asmodeus@.PacBell.COM (Jon Ballard (1-1-90)) Distribution: comp Organization: TREE BBS (916)332-4930 Sacramento, CA Lines: 54 In article <16698@venera.isi.edu> jas@ISI.EDU (Jeff Sullivan) writes: >Is there some problem with perl's srand and rand functions? [...] >#!/usr/bin/perl >srand; > >$total = $roll = int(1+rand(20)); > >while ($roll == 10) { > $roll = int(1+rand(20)); > $total += $roll; >} > >print $total,"\n"; [...] >I wrote a test program to run this a lot of times in a row to test it. >Here's the program: > >#!/usr/bin/perl >foreach (0..$ARGV[0]) { > print `roll`; >} > >Here's the output: > >17 >7 >7 >7 >18 >18 >8 >18 >19 >19 >9 >9 >19 >19 >19 >*24 >*24 >*24 [... etc] Doesn't srand with no arguments take the current time as the seed value? Look like its doesn't look random becuase the seed value is the same untill another second click. If so then that why it doesn't look so random. You could always d something weird like "srand (time + $$)" to set the seed. -- Jonathan Ballard (a.k.a Asmodeus) UNIX Tree BBS - A new generation in BBS programs! EMAIL: csusac.ecs.csus.edu!tree!asmodeus ...!pacbell!sactoh0!tree!asmodeus ...!ucbvax!ucdavis!csusac!tree!asmodeus