I'm trying to pick up C++ and seems like I've hit a wall. I'm writing something that needs a random number. I know there are better alternatives to rand() but after so many hours of trying to figure out what's wrong... it's personal. This is something I wrote to reproduce the problem:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int i,random;
srand(time(NULL)); //initialize
for(i=0;i<100;i++)
{
random = rand();
printf("%d\n",&random); // keeps outputting 6422312
}
return 0;
}
This keeps outputting the same 'random' number everytime rand() is called. I'm using Atom to write on a Windows laptop. I've searched all over the site but I still can't figure it out. Thank you in advance for your help.
Aucun commentaire:
Enregistrer un commentaire