Trying to generate random random numbers!

Trying to generate random random numbers!

Post by Jonathan I. Kame » Tue, 19 Mar 1991 14:40:12




|> 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

Office: 617-253-8085                          Home: 617-782-0710

 
 
 

Trying to generate random random numbers!

Post by Miles ONe » Tue, 19 Mar 1991 14:06:43


Quote: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


 
 
 

Trying to generate random random numbers!

Post by Peter La » Tue, 19 Mar 1991 20:42:28




>|> 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

Integrated Systems Laboratory
ETH-Zentrum, 8092 Zurich

 
 
 

Trying to generate random random numbers!

Post by Sanyee Ta » Tue, 19 Mar 1991 12:16:39


Obviously your seed doesn't work, the randow number generator simply takes a
default seed.  What machine and what kind function call you use?  
 
 
 

Trying to generate random random numbers!

Post by Metallica Rul » Mon, 01 Apr 1991 06:32:26




>|> 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
--

 
 
 

1. Random Number generator not Random *****

Hi:

        I am using random()&01 to get a binary random
number. Turns out if I generate more than 50 numbers,
the last 30 or more are all 1s or 0s, i.e., my random
number generator is not random!

        Worse, if I generate 500 numbers, 497 are 1s.
The fraction of consistent numbers increases as the number
of trials increases.

        Any clues? Anybody got a pointer to an FAQ where
I can get a random number generator that is random?

Thanks in advance,

-Badri

2. Internet connection failing for no reason.

3. Generating Random Numbers

4. Odd font prob. in OpenOffice

5. Random number generating script

6. Problem with NAT

7. generating random numbers (FAQ??)

8. loginrestrictions

9. using nawk to generate a random number

10. Generating a random hex number in bash

11. generating random numbers

12. generating random number in sh