I wanna make the program pick a number randomly between 1 and 15. What's the script for that. Also, how do you assign that number to a varible.
Thanks!
Printable View
I wanna make the program pick a number randomly between 1 and 15. What's the script for that. Also, how do you assign that number to a varible.
Thanks!
Read the faq.
Now how do ya assign the number to a varible?
>Now how do ya assign the number to a varible?
Using the function name from the faq...
Code:int mynum;
mynum = rand_mid(1, 15)
Using the time to seed a random number isn't a bad idea.
Here is one solution.
-----
srand(static_cast<unsigned>(time(0)));
// random number 1 to 15
int rNum = static_cast<int>((((static_cast<double>(rand())) / (static_cast<double>(RAND_MAX + 1))) * 15 + 1));
-----
Kuphryn
simple
COOL PROGRAMS @ www.akilla.tkPHP Code:
#include <stdio.h> //for printf, etc
#include <time.h> //for time function in randomize()
#include <stdlib.h> //for randoming functions
main()
{
int i;
randomize()
for (i=1; i<=10; i++)
{
printf("%d\n", 1+ rand()%15 );
}
}