Ask coding questions

← Back to all posts
C++ srand() Random
LukeBreeden (0)

Hi, i'm working on a dice rolling project where I need random numbers for the rolls, and different numbers each time it's run. I know I need to change the srand(), but i don't know how to make the seed random. How do I make the srand() actually random?

Answered by AdobeZev (15) [earned 5 cycles]
View Answer
AdobeZev (15)

Use the time module
#include <stdlib.h>
#include <time.h>

LukeBreeden (0)

@AdobeZev Thanks, this helped a lot. I'm new to C++ and am just getting into other libraries. The only thing that I could think of was using rand(), but then it isn't random, so it would be an infinite loop of srand(rand()). This helps A LOT!