Skip to main content
GameDev.net gamedev.net
🔒 Locked

Random...

Started by DarkHunter Dec 1, 2001 at 11:24 AM 7 replies 950+ views
Original Post
DarkHunter
DarkHunter
How do i use random?? I remember somthing about srand() but i dont remember how to use it, and what headers and crap like that. Can sombody explain?
Shag
Shag
wrong forum ...

http://msdn.microsoft.com/library/
soreno
soreno
lib: cstdlib, ctime

code:

srand(time(0)); //seed the randomizer
int random = rand()%32; // random number 0->32
DarkHunter
DarkHunter
Thanks soreno, and im sry to bother you Shag, i really am!
DarkHunter
DarkHunter
One more thing, would that be any different if i were to get random char? or is it the same? And is there any openGL command to randomize things? like objects or somthing like that... Thanks
RabidChild
RabidChild
To get a random char, just do this:

  
char rchar;

srand(time(NULL));
rchar = rand()%128;


This works because all a char is in C is an integer with a different upper bound.

Edited by - RabidChild on December 1, 2001 1:15:47 PM
--Ben CarterRomans 8:38-39
soreno
soreno
say you want to create a random char (ascii value from 32 to 255):

char rchar;
srand(time(NULL));
rchar = (rand()%(255-32))+32;
DarkHunter
DarkHunter
hey soreno, thanks for the info AND you are a god with screen savers. Thanks for the update, it works on my pc and teachers pc too! Much faster then b4, thanks so much.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.