Effacer les filtres
Effacer les filtres

Non-repeating random integer generator with a seed

3 vues (au cours des 30 derniers jours)
Mohsin Shah
Mohsin Shah le 1 Août 2017
Commenté : Mohsin Shah le 1 Août 2017
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?

Réponse acceptée

James Tursa
James Tursa le 1 Août 2017
Modifié(e) : James Tursa le 1 Août 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

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by