up
previous
next
seed for
Rand
This function seeds the random number generator,
Rand.
NB: every time you restart CoCoA the sequence of random numbers will
be the same (as in other programming languages). If you want total
randomness see the example below.
Seed(5);
Rand();
1991603592
-------------------------------
Rand();
-1650270230
-------------------------------
Seed(5); -- with the same seed, "Rand" generates the same sequence
Rand();
1991603592
-------------------------------
Rand();
-1650270230
-------------------------------
-- Total randomness:
-- the following shows how to make a ramdom seed based on the date.
D := Date();
D;
Mon Mar 02 14:43:44 1998
-------------------------------
Seed(Sum(Ascii(D)));
|