Non-repeating random integer generator with a seed

4 Ansichten (letzte 30 Tage)
Mohsin Shah
Mohsin Shah am 1 Aug. 2017
Kommentiert: Mohsin Shah am 1 Aug. 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?

Akzeptierte Antwort

James Tursa
James Tursa am 1 Aug. 2017
Bearbeitet: James Tursa am 1 Aug. 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

Weitere Antworten (0)

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by