Azzera filtri
Azzera filtri

Non-repeating random integer generator with a seed

4 visualizzazioni (ultimi 30 giorni)
Hello, How to generate random integers with a seed value. I know about randi and ranperm. rnadi can use a seed value to generate random integers but the problem is repetition. On the other hand, randperm can generate non-repeating random integers but I don't know to use seed with it. What is the solution if I use randi with seed to produce non-repeating random integers or if I use randperm with a seed value for generating the same random integers at the receiver side for the reverse process?

Risposta accettata

James Tursa
James Tursa il 1 Ago 2017
Modificato: James Tursa il 1 Ago 2017
According to the doc for randperm, it uses the same random number generator as rand, randi, and randn. So you can control the seeding with rng (even though randperm isn't mentioned in the rng doc). E.g.,
>> rng('default')
>> randperm(10)
ans =
6 3 7 8 5 1 2 4 9 10
>> randperm(10)
ans =
6 1 7 4 9 5 8 3 10 2
>> randperm(10)
ans =
2 10 8 9 1 5 7 6 3 4
>> rng('default')
>> randperm(10)
ans =
6 3 7 8 5 1 2 4 9 10
>> randperm(10)
ans =
6 1 7 4 9 5 8 3 10 2
>> randperm(10)
ans =
2 10 8 9 1 5 7 6 3 4

Più risposte (0)

Categorie

Scopri di più su Random Number Generation in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by