Pseudo random number sequence with non-repeating elements

6 Ansichten (letzte 30 Tage)
ANJANA KRISHNAN A
ANJANA KRISHNAN A am 12 Mär. 2017
Kommentiert: the cyclist am 12 Mär. 2017
I want to generate a pseudo random number sequence which doesn't repeat any of its elements.
For example,I need 25 elements in that sequence,the values of elements ranges from 1 to 25,and no elements should be repeated.(Actually,the number of elements i need in that sequence is very large).
Also,this sequence should be reconstructable (using a seed) later.
How can i do that?I read about randperm. But i think its not suitable in this case.

Antworten (1)

the cyclist
the cyclist am 12 Mär. 2017
Why do you think randperm is not what you need? It seems right to me.
rng(1234) % Set a seed for reproducibility
randperm(25) % Generate integers from 1:25, without replacement
  2 Kommentare
ANJANA KRISHNAN A
ANJANA KRISHNAN A am 12 Mär. 2017
This gives me actually what i need.Bt i'm not sure whether it will work that much fast for large number of elements.
the cyclist
the cyclist am 12 Mär. 2017
I'm not sure how fast you need. On my machine, this method generated 100,000,000 elements in 7 seconds.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements 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