La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.
Génération de nombres aléatoires
Valeurs initiales (graines), distributions, algorithmes
Utilisez les fonctions rand
, randn
et randi
pour créer des séries de nombres pseudo-aléatoires. Utilisez la fonction randperm
pour créer un vecteur d’entiers permutés de façon aléatoire. Utilisez la fonction rng
pour contrôler la répétabilité de vos résultats. Utilisez la classe RandStream
si vous avez besoin d’un contrôle plus avancé de la génération de nombres aléatoires.
Fonctions
Rubriques
Générer des nombres aléatoires
- Create Arrays of Random Numbers
Userand
,randi
,randn
, andrandperm
to create arrays of random numbers. - Random Numbers Within a Specific Range
This example shows how to create an array of random floating-point numbers that are drawn from a uniform distribution in the open interval (50, 100). - Random Integers
This example shows how to create an array of random integer values that are drawn from a discrete uniform distribution on a specific set of numbers. - Random Numbers from Normal Distribution with Specific Mean and Variance
This example shows how to create an array of random floating-point numbers that are drawn from a normal distribution having a mean of 500 and variance of 25. - Random Numbers Within a Sphere
This example shows how to create random points within the volume of a sphere, as described by Knuth [1]. - Why Do Random Numbers Repeat After Startup?
Avoid repetition of random number arrays when MATLAB® restarts. - Replace Discouraged Syntaxes of rand and randn
Replace Discouraged Syntaxes ofrand
andrandn
.
Contrôler la génération de nombres aléatoires
- Controlling Random Number Generation
This example shows how to use therng
function, which provides control over random number generation. - Generate Random Numbers That Are Repeatable
This example shows how to repeat arrays of random numbers by specifying the generator algorithm and seed first. Every time you initialize the generator using the same algorithm and seed, you always get the same result. - Generate Random Numbers That Are Different
This example shows how to avoid repeating the same random number arrays when MATLAB restarts.
Contrôler plusieurs séries ou sous-séries
- Managing the Global Stream Using RandStream
This example shows how to use theRandStream
class to control random number generation from the global stream. - Multiple Streams
This example usesRandStream
to create multiple, independent random number streams. - Creating and Controlling a Random Number Stream
This example shows how to useRandStream
to create random number streams and substreams.