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...

## Recommended Answers

Jump to Postcouldn't you just fill an array with numbers from 1-100.

Then shuffle them inside the array?

Jump to PostWhat do you mean by 'random'? What is the range of these numbers? If they're numbers from 0 to 99, then you can prefill the array, do a random_shuffle on them, and then go through the array looking for numbers at their own indices. Whenever you get them, swap them …

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 …

## 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, learning, and sharing knowledge.