Sanyee_Tang@mindlink.UUCP (Sanyee Tang) (03/18/91)
Obviously your seed doesn't work, the randow number generator simply takes a default seed. What machine and what kind function call you use?
meo@Dixie.Com (Miles ONeal) (03/18/91)
Michael A. Sapienza writes:
!I could use some help in generating random numbers. The problem I am having
!is that I get the same set of numbers each time that I run the program. I
!have tried using srandom (seed) and entering the seed from the keyboard,
!but this also returns the same random number. Any help would be greatly
!appreciated!
On what? Using what?
Sounds like your srand() (srandom?) is broken. But the easy way
(if srand() works) is to say
srand ((int) time (0));
(assuming you are on a UNIX system).
You might also check out the drand48() man page.
-Miles
Miles O'Neal
meo@dixie.com {uunet | emory}!rsiatl!meo
jik@athena.mit.edu (Jonathan I. Kamens) (03/18/91)
In article <7161@bgsuvax.UUCP>, sapienza@bgsuvax.UUCP (Michael A. Sapienza) writes: |> I could use some help in generating random numbers. The problem I am having |> is that I get the same set of numbers each time that I run the program. I |> have tried using srandom (seed) and entering the seed from the keyboard, |> but this also returns the same random number. Any help would be greatly |> appreciated! I have no problem at all using srandom() and random() to get random numbers, and I expect most of the other readers of this newsgroup have no problem either, so it's really impossible for us to diagnose the problem you are having unless you tell us more specifically exactly what your code is doing. For example, it would help if you would provide a short test program that doesn't work (i.e. gets the same random numbers each time) for you. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710
prl@iti.org (Peter Lamb) (03/18/91)
jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <7161@bgsuvax.UUCP>, sapienza@bgsuvax.UUCP (Michael A. Sapienza) writes: >|> I could use some help in generating random numbers. The problem I am having >|> is that I get the same set of numbers each time that I run the program. I >|> have tried using srandom (seed) and entering the seed from the keyboard, >|> but this also returns the same random number. Any help would be greatly >|> appreciated! > I have no problem at all using srandom() and random() to get random numbers, >and I expect most of the other readers of this newsgroup have no problem >either, so it's really impossible for us to diagnose the problem you are >having unless you tell us more specifically exactly what your code is doing. >For example, it would help if you would provide a short test program that >doesn't work (i.e. gets the same random numbers each time) for you. There was a bug in (s?)random() in Ultrix 2.0 and 2.2, where srandom calls with the same seed did not generate repeatable sequences. This seems to be fixed in Ultrix 4.0, at least the RISC version. The response from DEC at the time was that it should be fixed in 3.0. For Michael, you should specify at least the OS version and hardware you are having problems with for queries like this. A small code example as Jonathan suggests also makes it easier for people to help you. -- Peter Lamb uucp: uunet!mcsun!ethz!prl eunet: prl@iis.ethz.ch Tel: +411 256 5241 Integrated Systems Laboratory ETH-Zentrum, 8092 Zurich
savage@tigger.Colorado.EDU (Metallica Rules) (03/31/91)
In article <1991Mar18.054012.24970@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes: >In article <7161@bgsuvax.UUCP>, sapienza@bgsuvax.UUCP (Michael A. Sapienza) writes: >|> I could use some help in generating random numbers. The problem I am having >|> is that I get the same set of numbers each time that I run the program. I >|> have tried using srandom (seed) and entering the seed from the keyboard, >|> but this also returns the same random number. Any help would be greatly >|> appreciated! > I have encountered the problem before, and my soulution to it has been to seed the generator with a diriviative of the seconds in the clock/time. Because each of the seconds in the time keep increasing from I think 1 Jan 1970. So each seed will be different then the others, and you will always or should get a different rand each time you run it. Hope this helps... Chuck -- savage%tigger@boulder.colorado.edu