1. ## Good ramdomize/distribution algorithm?

Hi, I got a problem.

Lets say I got a list with 100 free spots.

I want save something in 60 spots, and I want do distribute them as evenly as possible. That is I don't want spot 1-59.

Anyone got any suggestions on how to solve this in a good way?

Thanks

2. I'm sorry, I don't really understand what you mean by "That is I don't want stop 1-59".

3. Code:
`r = rand() % 100;`
perhaps?

--
Mats

4. Originally Posted by Abda92
I'm sorry, I don't really understand what you mean by "That is I don't want stop 1-59".
ok, lets say the list is 10 long

That is I don't want place: 1,2,3,4, I want like: 1,3,5,7, I don't wan't clusters.

If so, you probably need to KNOW what you are trying to achieve, and implement an algorithm for that. My suggestion will still work to spread it around, but there's absolutely no guarantee that you don't get 1, 2, 4, 7 as a sequence of 4.

--
Mats

6. Basically, you want to choose 60 integers from 1 to 100 inclusive such that they are distributed as evenly as possible. One way is to choose all the odd numbers, then choose every 10th even number.

EDIT:
But if matsp's guess is correct, then obviously this choice is not a one time thing. Consequently, just choose at random, in the long run things will even out even if the first time you get 1-59.

7. Originally Posted by micke_b
Lets say I got a list with 100 free spots.
The problem makes no sense. Lists don't have 'free spots'. Lists only contain exactly what items you put in them and are always accessed sequentially.
Perhaps you mean an 'array'?

Are you doing hashing, and want to distribute items into an array without clumping so as to reduce collisions or something?