hi all,
I am required to generate an array having 100 random numbers, where there is absolutely no repetition and the case where the ith element of the array is the number " i " itself is not allowed ..
I found some ideas where we could generate pseudo random numbers using the idea:
x(n+1) = (x(n)*P1 + P2) (mod N) .
where x(n) is the nth element,
P1 and P2 are constants
N is also a constant.. the value of x0 must be chosen appropriately..
This does not guarantee absolute randomness..
Can some one help me with this please...
kris.c 0 Newbie Poster
Recommended Answers
Jump to Post>Now, check for any repeated numbers, or numbers that are on the index
>same as themselves using recursion; change the number again using
>another rand() call. keep track of the number of changes made.
Theoretically, this could be a neverending process. It's also very complicated, and I'm surprised it's the …
Jump to Post>@Narue Care to try your hand at the problem youself?
The easiest solution would be to restrict the range to numbers greater than the largest index in the array. That ensures that none of the numbers will match an index. Then you can insert random numbers into a binary search …
Jump to Post>But you had to think didn't you?
Only because lately I haven't been able to think straight. ;)
All 10 Replies

iamthwee
Exodust 0 Newbie Poster
kris.c 0 Newbie Poster
kris.c 0 Newbie Poster
Rashakil Fol 978 Super Senior Demiposter Team Colleague
Narue 5,707 Bad Cop Team Colleague
Exodust 0 Newbie Poster
Narue 5,707 Bad Cop Team Colleague
Exodust 0 Newbie Poster
Narue 5,707 Bad Cop Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.