Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Damien Doligez <Damien.Doligez@inria.fr>
To: caml-list@inria.fr
Subject: Re: Nombre aléatoire.
Date: Sat, 23 May 1998 16:00:40 +0200	[thread overview]
Message-ID: <199805231400.QAA24954@tobago.inria.fr> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1298 bytes --]


[English summary:
The pseudo-random number generator does not give random numbers.
You have to initialize it, or it will always give out the same
sequence of numbers.]

>From: Patrice AUFFRET <patrice.auffret@hol.fr>
> Mais lorsque je compile le
>programme, j'obtiens toujours le meme nombre.

Eh oui, Caml est un langage déterministe, ce qui veut dire que le même
programme donne toujours le même résultat, à moins de faire des
entrées-sorties (au sens large: toute communication avec le système
d'exploitation est une entrée-sortie).

Il faut donc donner au générateur de nombres pseudo-aléatoires un
point de départ à partir duquel il pond une suite de nombres.
En général, on utilise la date et l'heure comme donnée de départ.

Le générateur ne le fait pas lui-même car il est souvent utile de
pouvoir répéter une exécution à l'identique (par exemple pour déboguer
ou pour refaire une simulation).


> Le compilateur crée un
>nombre qu'il gardera de manière permanante lors de l'exécution
>ultérieure du programme.

Pas vraiment.  Le compilateur est parfois subtil mais jamais méchant.


>Comment faire pour qu'il change à chaque
>exécution du programme compilé ?

Vous devez utiliser la fonction Random.init ou Random.full_init
(random__init, random__full_init en Caml Light).

-- Damien





             reply	other threads:[~1998-05-23 22:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-23 14:00 Damien Doligez [this message]
  -- strict thread matches above, loose matches on Subject: below --
1998-05-21 16:40 Patrice AUFFRET
1998-05-22  7:26 ` Jean-Christophe Filliatre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199805231400.QAA24954@tobago.inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox