View Single Post
  #2 (permalink)  
Old 07-21-2008, 01:33 PM
MeTh0Dz|Reb0rn's Avatar   
MeTh0Dz|Reb0rn MeTh0Dz|Reb0rn is offline
My Posts Are Moderated
 
Join Date: Jul 2008
Posts: 17
Rep Power: 0
MeTh0Dz|Reb0rn is an unknown quantity at this point
Default Re: Random.. not actually random

Yeah I think so because most algorithms take some kind of seed such as the current time or the size of some file. If it always uses the same seed then the algorithm should in theory return the same number. Correct?

All you would have to do to find out is something like this. *I can't do currently because I am at work*

Code:
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;
 
int main() {
    int seed_numb = 5;
    srand(seed_numb);
    cout << rand() % 10 << endl;
    Sleep(500);
    cout << rand() % 10 << endl;
    Sleep(500);
    cout << rand() % 10 << endl;
    getch();
    return 0;
}
That should print the same thing everytime.
Reply With Quote