Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Re: on non unix platform
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-05-28 (15:07)
From: Martin Quinson <mquinson@z...>
Subject: Re: on non unix platform
> >From: Martin Quinson <>
> >How can I write this without the unix library ?
> >
> >Random.init (int_of_float (Unix.time ()));;
> You can do:
>     Random.init (int_of_float (Sys.time ()));;
> or you can input a random seed from the user and give it as argument
> to Random.init.

                        (francais en bas)

hmmm. from htmlman/module sys :

> val time: unit -> float
>          Return the processor time, in seconds, used by the program since the
> beginning of execution.

So, if this call is at the begining of the programm, it will allways generate 
the same number (or almost). from the source code :
(* Simple initialisation.  The seed is an integer.
   Two seeds that are close enough will not produce uncorrelated
   pseudo-random sequences.

And I really dislike the second solution...

Maybe would it be possible to make the module Random initialize itself alone 
before the first call, in the next release...

                             [en francais]

J'aimerais initialiser le generateur aléatoire de nombre sans utiliser la 
librairie Unix. Dans d'autres langage, j'ai l'habitude d'utiliser l'heure pour 
ca, mais, apparament, c'est impossible sans la librairie Unix (ce qui n'est 
pas portable, oblige a recompiler le top-level et complique la ligne de 
compilation des compilateurs)

Quant à l'idée de demander une graine à l'utilisateur, je trouve ca un peu 
préhistorique, comme approche. ;)

A mon avis, le plus simple serait encore que le module Random se charge tout 
seul comme un grand de s'initialiser sans demander a l'utilisateur de le faire.
(dans une prochaine version ?)

Merci & thanks,