How to generate random (2 integer number) pair from the given values (say integer from 1-10) without repeating the integer number?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SANDEEP SINGH RANA
am 28 Dez. 2021
Kommentiert: Image Analyst
am 28 Dez. 2021
Hi,
I want to generate pair of 2 values from the given values so that values or number donot repeat.
For example, for the value 10, i want to generate pair of 2 values assign or save in matrix.
It should give me matrix like: (1, 7), ( 2,9), (3,5), (4,6),(8,10). { Any 2 integer value pair}
Thanks and Regard
1 Kommentar
Image Analyst
am 28 Dez. 2021
What exactly does "generate pair of 2 values" mean?
Do you want to generate a pair (one single pair), or 5 pairs (like you showed)?
Are the "given values" determined from your number (like 1 to N where N (10) is your number), or can it be any 2-column matrix where you specify the values (like you have a list of 1000 rows and 2 columns and need to pick one random row/pair from that given list of pairs)?
Akzeptierte Antwort
Voss
am 28 Dez. 2021
If I understand correctly that there should be no repeated values anywhere in any pair, you can do this:
N = 10;
reshape(randperm(N),[],2)
0 Kommentare
Weitere Antworten (0)
Siehe auch
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!