 |
|
List Archives > 
Maple User Group List Archive > 
Archive by date > 
This Month By Date > 
This Month By Topic
[MUG] Re: Does the rand() function really give random numbers?
| [MUG] Re: Does the rand() function really give random numbers? |
|
Author: Maple Group
Posted: 29/01/2001 19:08:54 GMT
|
Subject: Does the rand() function really give random numbers?
"Random number generators" on computers are almost always actually
pseudo-random number generators. They produce a sequence of numbers
using a deterministic algorithm. If you use the same seed to start
the "random" number generator, you always get the same sequence. This
can be either good or bad, depending on your point of view. Maple
always starts the seed off at 1. If you use the "randomize" function
with no argument, it will set the seed to a value based on the system
clock, and the subsequent sequence of "random" numbers will be different.
But if you want "numbers that really ARE random", it basically can't be
done in software.
Robert Israel
Department of Mathematics http://www.math.ubc.ca/~israel
University of British Columbia
Vancouver, BC, Canada V6T 1Z2
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 25 Jan 2001 21:19:32 -0500 (EST)
From: Edwin Clark
To: Nathan Sokalski
Subject: Does the rand() function really give random numbers?
Well, the short answer is that you cannot. Many will
probably send you the famous statement of von Neumann:
Anyone who considers arithmetical methods of producing
random numbers is, of course, in a state of sin.
The Maple rand operator is essentially a linear
congruential generator. For a useful and entertaining
introduction to such matters see Knuth's book
The Art of Computer Programming Vol 2--from which
the above quote was taken. By the way, I once previously
raised the question of exactly how good the Maple
rand operator is on this forum and got no replies.
So maybe there are no experts on (pseudo) random
number generators on this list?
--Edwin Clark
------------------------------------------------------
W. Edwin Clark, Math Dept, University of South Florida,
http://www.math.usf.edu/~eclark/
------------------------------------------------------
God created the null set and brackets; all the rest
is the work of Man.--Kronecker [updated by Paul Chernoff]
------------------------------------------------------
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Thu, 25 Jan 2001 21:30:30 -0500 (EST)
From: Carl DeVore
To:
Subject: Does the rand() function really give random numbers?
The random number sequence is simply an arithmetic progression
r[1], r[2], ..., r[n]
of finite length over a finite field with a very large characteristic. In
other words, the formula is
r[k+1]:= (a * r[k]) mod p
where a and p are very large hard-coded integers. You can print out the
very simple code for "rand" and see for yourself:
> interface(verboseproc= 3);
> print(rand);
The starting place in the sequence is determined by a global variable
named _seed. After you do a restart, _seed is set to 1. The procedure
"randomize" will set the value of _seed to some value based on the
computer's clock. So the easy solution to your problem is to once, in the
initialization code of your program, put the command "randomize();".
If you are using Maple to solve MasterMind logic problems, then I am very
interested in your project. Please tell me about it.
Carl Devore
University of Delaware
-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-=*=-
Date: Fri, 26 Jan 2001 08:21:12 +0100
From: Heike Koch-Beuttenmueller
To:
Subject: Does the rand() function really give random numbers?
It is normal thath the rand() - functions give the same sequence of
random numbers. For testing programs it is very useful of course. To get
different starting values , you can use randomize , for example:
restart;rand();
427419669081
> Seed:=randomize();
Seed := 980493650
> for i from 1 to 10 do
> rand();
> end do;
423631740631
701796052445
693596754556
242124931457
749125719897
963739144968
159578065105
515648360085
115409797637
254328354262
Mit freundlichen Gruessen
Heike Koch-Beuttenmueller
|
[View Complete Thread]
Previous by date: [MUG] integral - correct for evalf(Int(f)), incorrect for int(f), Robert J Gooding
Next by date: [MUG] Re: Listing all variables, Maple Group
Previous thread: [MUG] logical operations in maple, Guy-Armand Kamendje
Next thread: [MUG] Listing all variables, Francois DEBROUCKE
|
|
|