So, as we all know.. no one is going to fool us.. There is nothing that is completely random, when in a programming language we make something like Random() it's not really random, it takes some variable and follows an algorithm...
Now my question is, if we find a method to 'freeze' the computer and keep it in the same state, would the 'random' number be always the same? or it will still output a different number?
Random.. not actually random
Started by TcM, Jul 21 2008 06:09 AM
30 replies to this topic
#1
Posted 21 July 2008 - 06:09 AM
|
|
|
#2
Posted 21 July 2008 - 09:33 AM
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*
All you would have to do to find out is something like this. *I can't do currently because I am at work*
#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.
#3
Posted 21 July 2008 - 09:50 AM
I don't know any C/C++?
But I kinda understood that, although you are using rand(), and that might output a different number each time, unless you 'freeze' the pc environment as I said in my 'theory'
And yes, that's what I meant, if they take a variant seed number, and we manage to freeze the PC so all variants are the same... that means all seeds will be the same.. that means, the random number won't be much of a random number
But I kinda understood that, although you are using rand(), and that might output a different number each time, unless you 'freeze' the pc environment as I said in my 'theory'
And yes, that's what I meant, if they take a variant seed number, and we manage to freeze the PC so all variants are the same... that means all seeds will be the same.. that means, the random number won't be much of a random number
#4
Posted 21 July 2008 - 09:55 AM
You could always test, next time your computer hangs :)
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#5
Posted 21 July 2008 - 10:00 AM
That should output the same number everytime. If I am not mistaken, rand() takes the seed whatever it is and runs it through an algorithm then returns a value, so in theory a certain number should always return the same number. That is why you will often times see people using srand(time(NULL)), because the seconds change often enough that you won't often have repeated numbers unless your program runs for an extended period of time.
Hence by using the same seed you would be emulating this freezing.
Using something like memory, or characters in a text or something as the seed would require the freezing of the computer probably.
Hence by using the same seed you would be emulating this freezing.
Using something like memory, or characters in a text or something as the seed would require the freezing of the computer probably.
#6
Posted 21 July 2008 - 10:25 AM
Well, if my PC hangs, it won't be able to generate a random number... right?
#7
Posted 21 July 2008 - 10:39 AM
Lol, well yeah. All I am saying is that a random number generator is going to give you the same value every time for the same seed. The algorithm takes a number, runs it through it's equation and then returns a value that was derived from this orginal value.
That is why it is perfered to use a seed that is everchanging.
That is why it is perfered to use a seed that is everchanging.
#8
Posted 21 July 2008 - 10:44 AM
Ok, what would be an ideal seed?
#9
Posted 21 July 2008 - 10:50 AM
An ideal seed?
Something like time, which will vary constantly. Even if you use the given C/C++ time function, you are returned the seconds past midnight, so that will change every second. That should be good enough for most of our random number needs.
Another possible seed is the amount of virtual memory currently being used, which is going to be varrying quite a bit.
The size of a file in a computer's root drive, or the system folder. You could set it to go through like 10 or 15 files with a for statement or something so you won't be getting the first one. Although in many circumstances it won't matter.
The number of files in a given directory, maybe not the best choice.
Those are some examples, stuff that varies constantly is usually a good choice. And depeneding on how you need to use the random number it can just be stuff that varies from computer to computer.
If you google good random number seeds there will be alot more there than what I had to say. And also if you look into polymorphism it will give you some examples of what to use as a random number seed.
Something like time, which will vary constantly. Even if you use the given C/C++ time function, you are returned the seconds past midnight, so that will change every second. That should be good enough for most of our random number needs.
Another possible seed is the amount of virtual memory currently being used, which is going to be varrying quite a bit.
The size of a file in a computer's root drive, or the system folder. You could set it to go through like 10 or 15 files with a for statement or something so you won't be getting the first one. Although in many circumstances it won't matter.
The number of files in a given directory, maybe not the best choice.
Those are some examples, stuff that varies constantly is usually a good choice. And depeneding on how you need to use the random number it can just be stuff that varies from computer to computer.
If you google good random number seeds there will be alot more there than what I had to say. And also if you look into polymorphism it will give you some examples of what to use as a random number seed.
#10
Posted 21 July 2008 - 11:57 AM
Quote
polymorphism
#11
Posted 21 July 2008 - 12:05 PM
#12
Posted 21 July 2008 - 12:18 PM
Would it be possible to take more than one seed, combine them and make a more 'unique' and 'random' output?


Sign In
Create Account


Back to top









