# Thread: biased random numb generation

1. ## biased random numb generation

hi everyone

i need to generate a bunch of random numbers that will be influenced by some number (a positive integer say up to a 1000) and i need to have these biased random numbers within a certain range (from 1 to 44).

i managed to generate purely random numbers within my range
witht the rand function:

Code:
`some_array[i] = rand() % 45;`
but how do i influence the rnd number generation?

2. I'm not sure I understand what you mean by biased random number or influenced. Do you want more of the generated numbers to be in a certain region from 1 to 44. For example, do you want something like this?

sometimes the random number is between 1 to 21

often the random number is between 21 and 33

usually the random number is between 33 to 44

If this is what you want I think I know how to do what you want and I'll explain.

3. Are you talking about generating numbers with a poisson distribution, where values closer to the mean are more likely than those at the limits?

4. nothng too fancy. i was thinking more a random number multiplied with some fixed number. this way the result will still be random but not purely random as it would be with just using rand()

i tried this code:

Code:
`array[i] = (y * rand()) % 45;`
where y is some integer.
now this thing sometimes works and sometimes it doesnt.
when i run it sometimes it gives me zeros and other times positiver integres up to 44 (as i want). why dooes it give me zeros sometimes?

5. > why dooes it give me zeros sometimes?
Because x % N
produces results in the range 0..N-1

If you want 1..N, then its
x % N + 1