-
How to randomize?
Alrite...im using MSVC++...i am also teaching myself...and am not that far along...but i really want to get this randomizing thing...and the examples given in the FAQ didnt work...with the exception of this one:
#include <stdlib.h>
int rand(void);
#include <stdlib.h> //for rand
#include <stdio.h> //for printf
int main(void)
{
randomize();
printf("A random number from 0 to 99: %d", rand() % 100);
return 0;
}
So if someone could either show me a different way...or explain to me why this one works that would be great ;P
-
/*#include <stdlib.h>
int rand(void);*/ take that part out ;P
#include <stdlib.h> //for rand
#include <stdio.h> //for printf
int main(void)
{
randomize();
printf("A random number from 0 to 99: %d", rand() % 100);
return 0;
}
-
#include <iostream.h>
int main()
{
int this = rand() %11;
return 0;
}
err....something like that i dont remember really good
but 11 is the number that randomizes from 1 -10 (im not sure why the extra 1 isnt counted) but thats sorta the idea. You should ask other poeple how do that
-
>>but 11 is the number that randomizes from 1 -10
you mean;
Code:
int this = (rand() %10)+1;
-
before u use rand() u have to use srand(value) and substitute a value for value. If u don't want the same results everytime, use this inside srand: time(NULL) and make sure to include time.h
-
ah thanks...havent tried it yet...but im sure it works ;P
-
yes it works! great! now just one more thing...(yea...lol) how do you set a lowest number? like if i wanted to randomize between 45 and 85 or something like that? i looked at the FAQ again...and it had this as well...but it didnt explain it well enough to me(yea im a newbit when it comes to programming~)
-
rand()%range+minimum
where:
range=highest number-lowest number+1
minimum=lowest possible number
-
wow you guys are great...heh mebbe i should register...i think i may start frequenting this board~