Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!lll-winken!decwrl!adobe!heaven!glenn From: glenn@heaven.woodside.ca.us (Glenn Reid) Newsgroups: comp.sys.next Subject: Re: random number generator Summary: seed with the system clock Message-ID: <385@heaven.woodside.ca.us> Date: 2 Jan 91 05:08:59 GMT References: <7781@umd5.umd.edu> Reply-To: glenn@heaven.woodside.ca.us (Glenn Reid) Organization: RightBrain Software, Woodside, CA Lines: 31 In article <7781@umd5.umd.edu> matthews@is-next.umd.edu (Mike Matthews) writes: >the random numbers aren't really random. They always start at the same thing. >Now, I know a little about how this works, and I know it has something to do >with setting the seed (or the state -- I'm using the newer random() function), >but how can I set *that* randomly every time the script is run? You're right; they're actually called "pseudo-random" number generators, because the pattern of numbers they generate is not likely to repeat in any observable patterns, but they're not really random. The usual approach is to seed the random number generator with the number of ticks of the system clock, which can be obtained with the "time()" system call. That number is very much what you or I would consider "random" since it changes once a second, but you can't keep sampling the time in your loop because the sequence will not be random. Try something like this (although I haven't tested it): long your_random_number; srandom ( (int)time(0) ); your_random_number = random(); I hope this helps. Glenn -- Glenn Reid RightBrain Software glenn@heaven.woodside.ca.us PostScript/NeXT developers ..{adobe,next}!heaven!glenn 415-851-1785