1. ## rand();

well im triing to get random numbers between say 23 and 35. if i use rand()%35 than it picks numbers between 0 and 35. what can i do.

2. Get a random number between 0 and 12, then add 23. Simple.

3. >well im triing to get random numbers between say 23 and 35.
r = ( rand() * ( 35 - 23 ) ) / RAND_MAX + 23;

>if i use rand()%35 than it picks numbers between 0 and 35.
Small ranges like that are frighteningly not random, so you'd best stick with the code I gave above. It uses the high order bits of a value instead of the low order bits which your method uses.

-Prelude

4. Originally posted by Prelude
>well im triing to get random numbers between say 23 and 35.
r = ( rand() * ( 35 - 23 ) ) / RAND_MAX + 23;

>if i use rand()%35 than it picks numbers between 0 and 35.
Small ranges like that are frighteningly not random, so you'd best stick with the code I gave above. It uses the high order bits of a value instead of the low order bits which your method uses.

-Prelude
Assuming that rand() generates a random number uniformly among the integers 0 to RAND_MAX , your function will not draw numbers uniformly from 23,24,...35 . The reason being that r can be 35 if and only if rand() is RAND_MAX , the probablilty of that (assuming ideal behavior of rand()) is 1/(RAND_MAX+1) <=1/32768 ( the minimum permitted value of RAND_MAX is 32767 ) way less than 1/(35-23+1)=1/13

5. i use the following function in my program :
Code:
```int my_rand(int max)
{
return 1+rand()%(max);
}```
now call my_rand(20); to get a random number between 1 and 20.
replace the return with "return 23+rand()%(max)" and call the
function with my_rand(35); so you'll have your random number

remember to use
Code:
`srand(time(NULL));`
in your program to get real random numbers

6. >...in your program to get real random numbers
There's no such thing

7. @Hammer
>> There's no such thing
what do you mean?

8. what do you mean?
How do you think the rand function works? Numbers obtained through rand() are psuedorandom in nature and not truly random. There is a mathematical equation used to generate these numbers and not some little fairie that picks a number out of a hat when you call the function. An initial value called the seed, which can and should be reset using the srand function, is used along with the algorithm to generate a psuedorandom sequence of values via the rand function. If the same seed value is used, either through just using the default value or setting it to the same value each time your program starts, then you will see that you get the same set of "random" values every single time.

9. ## ahhh...

no need to get very complex...

int mynumber = 23+rand()%2;

but i dont know if this is more effective than the rest..

rand()%x gives you a number between 0 and x

23 + rand()%x gives you a number between
0+23 and x+23 ... in this case, 23 and 25

COOL PROGRAMS @ www.akilla.tk

10. well... that's what i thought thanks

11. A PC can never generate true random numbers without additional devices (such as environmental samplers, timed user input, etc). RNG (random number generator) is an algorithm and very predictable without an input which cannot be predicted (such as nanosecond delay between human key strokes, current ambient temperature inside the computer case at the time of sampling, etc).

12. What are true random numbers , how do you define true random numbers ? If I give you a sequence of 100,000 numbers between 0 and 1 , will you be able to say whether they are truly random or have been genrated by a RNG , if you plan to use a battery of statistical tests most of the good RNG's pass almost all of the statistical tests so you must have some other criterion .