|
-
Mar 5th, 2001, 01:50 PM
#1
Does windows have a random number function?
-
Mar 5th, 2001, 02:08 PM
#2
Monday Morning Lunatic
Don't think so, but the standard library does:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
void main() {
cout << rand() << endl;
}
rand returns a number between 0 and RAND_MAX.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 5th, 2001, 03:06 PM
#3
Frenzied Member
or this
Code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
cout<<1*rand()%6<<endl;
return 0;
}
-
Mar 5th, 2001, 03:44 PM
#4
How do i get one between 0 and 99?
-
Mar 5th, 2001, 04:08 PM
#5
Frenzied Member
on mine you would do 0*rand()%99
parksies I think you would do this
#include <iostream>
#include <cstdlib>
using namespace std;
void main() {
RAND_MAX = 99
cout << rand() << endl;
}
-
Mar 5th, 2001, 04:21 PM
#6
Monday Morning Lunatic
RAND_MAX is already defined -- use:
Code:
float myrand(float lower, float higher) {
return (((float)rand() / (float)RAND_MAX) * (higher-lower)) + lower);
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 5th, 2001, 04:28 PM
#7
Thanks, but both those return the same sequence of numbers each time.
-
Mar 5th, 2001, 04:39 PM
#8
Monday Morning Lunatic
Seed the random number using srand at the start of your program, using the time as stated earlier.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Mar 5th, 2001, 05:28 PM
#9
It STILL gives the same sequence of numbers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|