dwww Home | Manual pages | Find package

random(3)                  Library Functions Manual                  random(3)

NOM
       random, srandom, initstate, setstate - Générateur de nombres aléatoires

BIBLIOTHÈQUE
       Bibliothèque C standard (libc, -lc)

SYNOPSIS
       #include <stdlib.h>

       long random(void);
       void srandom(unsigned int graine);

       char *initstate(unsigned int seed, char state[.n], size_t n);
       char *setstate(char *state);

   Exigences  de  macros  de  test de fonctionnalités pour la glibc (consulter
   feature_test_macros(7)) :

       random(), srandom(), initstate(), setstate() :
           _XOPEN_SOURCE >= 500
               || /* glibc >= 2.19: */ _DEFAULT_SOURCE
               || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE

DESCRIPTION
       The random()  function uses a nonlinear additive feedback random number
       generator  employing a default table of size 31 long integers to return
       successive pseudo-random numbers in the range from 0 to  2^31 - 1.  The
       period  of  this  random  number generator is very large, approximately
       16 * ((2^31) - 1).

       La fonction srandom() utilise son argument comme « graine » pour engen-
       drer une nouvelle séquence de nombres pseudoaléatoires qui seront four-
       nis lors des appels à random(). Ces séquences  sont  reproductibles  en
       invoquant  srandom()  avec la même graine. Si aucune graine n'est four-
       nie, La fonction random() utilise automatiquement une graine  originale
       de valeur 1.

       The  initstate()  function allows a state array state to be initialized
       for use by random(). The size of the state array n is  used  by  inits-
       tate()  to decide how sophisticated a random number generator it should
       use—the larger the state array, the better the random numbers will  be.
       Current  "optimal"  values for the size of the state array n are 8, 32,
       64, 128, and 256 bytes; other amounts will be rounded down to the  nea-
       rest known amount. Using less than 8 bytes results in an error. seed is
       the seed for the initialization, which specifies a starting  point  for
       the  random  number  sequence,  and provides for restarting at the same
       point.

       La fonction setstate() modifie la table d'états utilisée par  la  fonc-
       tion  random().  La table d'états état est alors utilisée comme généra-
       teur de nombres aléatoires jusqu'au prochain appel  de  initstate()  ou
       setstate(). état doit d'abord être initialisée avec initstate() ou être
       le résultat d'un appel précédent à setstate().

VALEUR RENVOYÉE
       The random()  function returns a value between 0  and  (2^31) - 1.  The
       srandom()  function returns no value.

       La fonction initstate() renvoie un pointeur sur la table d'états précé-
       dente. En cas d'échec, elle renvoie NULL  et  errno  contient  le  code
       d'erreur.

       La  fonction setstate() renvoie un pointeur sur la table d'états précé-
       dente. En cas d'échec, NULL est renvoyé et errno contient le code d'er-
       reur.

ERREURS
       EINVAL Le paramètre état de setstate() était NULL.

       EINVAL Une  table  d'états  de moins de 8 octets a été fournie à inits-
              tate().

ATTRIBUTS
       Pour une explication des termes utilisés dans cette section,  consulter
       attributes(7).

       ┌─────────────────────────────────────┬──────────────────────┬─────────┐
       │InterfaceAttributValeur  │
       ├─────────────────────────────────────┼──────────────────────┼─────────┤
       │random(), srandom(), initstate(),    │ Sécurité des threads │ MT-Safe │
       │setstate()                           │                      │         │
       └─────────────────────────────────────┴──────────────────────┴─────────┘

STANDARDS
       POSIX.1-2001, POSIX.1-2008, 4.3BSD.

NOTES
       La fonction random() ne doit pas être utilisée dans des programmes mul-
       tithreadés  où  le  comportement doit être reproductible. Utilisez ran-
       dom_r(3) dans ce cas.

       La génération de nombres aléatoires est un  sujet  complexe.  Numerical
       Recipes  in C: The Art of Scientific Computing (William H. Press, Brian
       P. Flannery, Saul A. Teukolsky, William T. Vetterling ; New York : Cam-
       bridge  University  Press, 2007, 3e éd.) fournit une excellente discus-
       sion sur les problèmes pratiques de génération de noms aléatoires  dans
       le chapitre 7 (Random Numbers).

       Pour  une discussion plus théorique, qui aborde également en profondeur
       d'autres domaines, voir le chapitre 3 (Random Numbers) du livre de  Do-
       nald  E. Knuth The Art of Computer Programming, volume 2 (Seminumerical
       Algorithms), 2e éd. ; Reading,  Massachusetts :  Addison-Wesley  Publi-
       shing Company, 1981.

BOGUES
       D'après  POSIX, initstate() devrait renvoyer NULL en cas d'erreur. Dans
       la mise en œuvre de la glibc, errno est renseigné en cas d'erreur comme
       spécifié, mais la fonction ne renvoie pas NULL.

VOIR AUSSI
       getrandom(2), drand48(3), rand(3), random_r(3), srand(3)

TRADUCTION
       La  traduction française de cette page de manuel a été créée par Chris-
       tophe Blaess <https://www.blaess.fr/christophe/>, Stéphan  Rafin  <ste-
       phan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, Fran-
       çois Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe  Gué-
       rard  <fevrier@tigreraye.org>,  Jean-Luc  Coulon (f5ibh) <jean-luc.cou-
       lon@wanadoo.fr>, Julien Cristau <jcristau@debian.org>,  Thomas  Huriaux
       <thomas.huriaux@gmail.com>,  Nicolas François <nicolas.francois@centra-
       liens.net>, Florentin Duneau <fduneau@gmail.com>, Simon  Paillard  <si-
       mon.paillard@resel.enst-bretagne.fr>,    Denis   Barbier   <barbier@de-
       bian.org>, David Prévot <david@tilapin.org> et bubu <bubub@no-log.org>

       Cette traduction est une documentation libre ; veuillez vous reporter à
       la        GNU        General       Public       License       version 3
       ⟨https://www.gnu.org/licenses/gpl-3.0.html⟩ concernant  les  conditions
       de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.

       Si  vous découvrez un bogue dans la traduction de cette page de manuel,
       veuillez envoyer un message à ⟨debian-l10n-french@lists.debian.org⟩.

Pages du manuel de Linux 6.03   10 février 2023                      random(3)

Generated by dwww version 1.15 on Sat Jun 29 01:44:12 CEST 2024.