Generazione di numeri casuali
Semi, distribuzioni, algoritmi
Utilizzare le funzioni rand
, randn
e randi
per creare sequenze di numeri pseudocasuali e la funzione randperm
per creare un vettore di numeri interi permutati a caso. Utilizzare la funzione rng
per verificare la ripetibilità dei risultati. Utilizzare la classe RandStream
quando è necessario un controllo più avanzato sulla generazione di numeri casuali.
Funzioni
Argomenti
Generazione di numeri casuali
- Creazione di array di numeri casuali
Utilizzarerand
,randi
,randn
erandperm
per creare array di numeri casuali. - Numeri interi casuali
Questo esempio mostra come creare un array di valori interi casuali estratti da una distribuzione uniforme discreta su un insieme specifico di numeri. - 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
.
Controllo della generazione di numeri casuali
- 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.
Controllo di più flussi o sottoflussi
- 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.