Randomize
Simple easy straight forward question. I have looked around some on the net but have not seen how to do it yet, but here it is:
How do you randomize numbers in C or C++. I can do it in Java, Basic and Visual Basic, but not in C++. I do not know the command. Can someone help me out real quick. Thanks. I know it is kinda stupid.
#include <random.h>int i;srand(GetTickCount() /* or some other time function */);i = rand();
[edited by - rotos on July 12, 2002 3:29:40 PM]
Thanks but i do not have a random.h header file. I am using Microsoft Visual C++.
Sorry about that, it should be stdlib.h. I don''t know how I came up with random.h.
Thanks, that works in VC++. Also one other thing. Does it generate any unisgned int. Or what is its range?
One other thing. You use GetTickCount() but I don''t have that command either. What are some other commands. I am knew to C++.
RAND_MAX I believe... It''s defined in cstdlib, so have a look in there if you''d like. Off the top of my head I think it''s signed...
I got intrepid ''n looked it up for you: in stdlib.h, as included with MSVC++, RAND_MAX is defined as 0x7fff. So a range of -32768 to 32767.
I got intrepid ''n looked it up for you: in stdlib.h, as included with MSVC++, RAND_MAX is defined as 0x7fff. So a range of -32768 to 32767.
In ctime, could use time ( ... ).
Have a quick search through google for random numbers and c++.
Have a quick search through google for random numbers and c++.
July 12, 2002 02:59 PM
There is no such thing is a random number generator, its usually called a psudo-random number generator. since its close but not quite a good.
The documentation on rand should be on http://msdn.microsoft.com
Its not very good for small numbers...like under 5. Since it has a lot of reduncencies.
The documentation on rand should be on http://msdn.microsoft.com
Its not very good for small numbers...like under 5. Since it has a lot of reduncencies.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement