0

I'm trying to write some code in c++ for a game, and I need to use a random number generator. I want the computer to pick a number between 1 and 713, but it always picks 41.

int x;
x = wordbank.size();
int m;
m = rand() % x;

Here is my code. wordbank is a vector, and x is the size of wordbank(713). Can anyone help me?

Thank you

Noob
  • 1
  • 2
  • could it be the computers memory saving m? I have no idea honestly – Noob Oct 07 '20 at 09:36
  • Read the linked duplicates. They explain exactly why `rand()` always returns the same value for you. – t.niese Oct 07 '20 at 09:37
  • Don't use `rand() % N` for random numbers. It's horrible. Use `std::mt19937` as shown in the answers this was marked a duplicate of. Also, I recommend watching this 30min talk by Lavavej: https://www.youtube.com/watch?v=LDPMpc-ENqY – Nikos C. Oct 07 '20 at 09:39

0 Answers0