On 02/05/11 02:35, Ivo Seeba wrote:
> I have a question about random.
> If random number generating is in a file
> for i = 0 to 3 do print_int (Random.int 10);print_char ' ' done;;
> then it generates evevry time the same random number:
> 4 7 4 8
> C:\Documents and Settings\is\Desktop>ocaml file.ml <http://file.ml/>
> 4 7 4 8
> C:\Documents and Settings\is\Desktop>ocaml file.ml <http://file.ml/>
> 4 7 4 8
> C:\Documents and Settings\is\Desktop>ocaml file.ml <http://file.ml/>
> 4 7 4 8
> If it generating is in a command line:
> # for i = 0 to 3 do print_int (Random.int 10);print_char ' ' done;;
> 4 7 4 8 - : unit = ()
> # for i = 0 to 3 do print_int (Random.int 10);print_char ' ' done;;
> 8 5 0 7 - : unit = ()
> # for i = 0 to 3 do print_int (Random.int 10);print_char ' ' done;;
> 5 7 6 0 - : unit = ()
> # for i = 0 to 3 do print_int (Random.int 10);print_char ' ' done;;
> 2 4 2 0 - : unit = ()
> It generates different randoms.
> Can anybody say, how to generate different random numbers in different
> times in a file?

Simply use Random.self_init () once at the beginning of your program.


Martin

-- 
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html

Reply via email to