Non-repeating random integer generator with a seed
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohsin Shah
el 1 de Ag. de 2017
Comentada: Mohsin Shah
el 1 de Ag. de 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?
0 comentarios
Respuesta aceptada
James Tursa
el 1 de Ag. de 2017
Editada: James Tursa
el 1 de Ag. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Random Number Generation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!