Random number between 1 and 4000?

B

Blarney

Martin said:
Beginners often seem to believe that they have discovered new problems,
but that is rarely so. In fact, most problems they run into have been
encountered many rimes in the past. This is the reason that many
newsgroups have "Frequently Asked Question" lists (FAQs). It is
normally expected that a poster will have checked the FAQ _before_
posting. Sometimes people will complain that they had no idea that
there was a FAQ or where it might be. But it is also expected behavior
to follow a newsgroup before posting. In almost every newsgroup with a
FAQ, the FAQ itself or at least a document pointing to it will be posted
about twice a month. Another objection often seen is that new posters
don't know about these simple guidelines of looking for the FAQ or
following the newsgroup. This is similar to claiming that there is no
need to check which side of the road people drive on when one goes to
another country.

That's a poor analogy.

Most severe consequence of posting to a newsgroup without knowing the
simple guidelines: mental anguish

Most severe consequence of driving on the wrong side of the road in a
foreign country: death
 
A

Anders Arnholm

What on earth is that? If it can be written in ISO C, perhaps that's a
better idea. Several pretty decent PRNGs can be written in ISO C; see,
for example, <S%[email protected]>. Or if you
want the sledgehammer approach, do a websearch on the Mersenne Twister.

A good random function can unfortunalty not yet be written i ISO C.
Without getting into system dependent things you can't get a good
entropy data from any place. If you can precent a good way to get
strong entropy data within ISO C, I stand corrected, but I don't
know of any interface to such stuff without knowing about the OS.
arc4random(), entropy data from any place. If you can precent a good way
to get strong entropy data within ISO C, I stand corrected, but I don't
know of any interface to such stuff without knowing about the OS.
arc4random(), is a good interface for this, rand() isn't.

However as this goes outside ISO C it has to be considerd for
portability. Desinging the same bad stuff over and over again
to keep inside ISO C have no place in good programing. As little
and using platform specific non ISO C stuff on things that ISO C
is as good at.

/ Anders
 
P

Purush

If you are using a DOS based compiler use the function randomize().
This will reinitialise the random number generator. So that you will
not have the same set of random numbers every time.

Thanks
 
M

Mr John FO Evans

"Purush" said:
If you are using a DOS based compiler use the function randomize().
This will reinitialise the random number generator. So that you will
not have the same set of random numbers every time.
On my system I initialise the random number generator with the system time
this gives me a satisfactory new start on each run.
 
C

CBFalconer

Purush said:
If you are using a DOS based compiler use the function randomize().
This will reinitialise the random number generator. So that you
will not have the same set of random numbers every time.

Please don't give such misinformation. There is no such standard C
function as randomize. However, srand() does exist. Use it when
you don't want the generator to always produce the same sequence.

In addition, ensure you include adequate context for your replies.
For the means to do this on the broken google interface to usenet,
see below.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>
 
R

Richard Bos

Anders Arnholm said:
A good random function can unfortunalty not yet be written i ISO C.

Which is why I wrote PRNGs instead. For most applications, a good PRNG
is good enough, and those of us who do need a _real_ RNG know it.
arc4random(), entropy data from any place.

Impossible to implement reliably on many systems. Keyboard timing? You
get into trouble with CLI plumbing. Network timing? Not all machines are
networked. Brownian motion? Needs a TTC interface, and those are rare.

Richard
 
R

Richard Bos

[ Learn to quote! I'm led to believe that there is a button on Google
Broken Beta somewhere which will let you do so. ]
If you are using a DOS based compiler use the function randomize().

And what guarantee do you have that all DOS (_whose_ DOS, anyway?) based
compilers have this function? And that it works correctly with rand() in
all those compilers?

Richard
 
R

Randy Howard

Richard Bos wrote
(in article said:
Impossible to implement reliably on many systems. Keyboard timing? You
get into trouble with CLI plumbing. Network timing? Not all machines are
networked. Brownian motion? Needs a TTC interface, and those are rare.

Of course, on some current operating systems, the arrival time
of unsolicited spyware and virii could be used as an entropy
source, unless you can't sample them fast enough.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top