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 runs. 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?

Zavexeon (927)

Just use rand() % max + 1.
This'll generate a number from 1 to the max.

Ex: rand() % 6 + 1
That'll generate a number from 1 to 6, simulating a 6 sided dice.