Pseudo random number sequence with non-repeating elements
7 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
the cyclist
2017 年 3 月 12 日
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 件のコメント
the cyclist
2017 年 3 月 12 日
I'm not sure how fast you need. On my machine, this method generated 100,000,000 elements in 7 seconds.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!