CoCoA:Seed

From ApCoCoAWiki
Revision as of 10:02, 24 October 2007 by XMLBot (talk | contribs) (pushing XML rev. 1.46, again)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Seed

seed for Rand

Description

This function seeds the random number generator, <ttref>Rand</ttref>.

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.

Example

  Seed(5);
  Rand();
1991603592
-------------------------------
  Rand();
-1650270230
-------------------------------
  Seed(5);  -- with the same seed, <quotes>Rand</quotes> 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)));

Syntax

Seed(N:INT):INT

Rand

   <type>integer</type>
   <type>miscellaneous</type>