|
||||||
| Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
| Sponsored Links |
|
|
|
|||||
|
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;
}
__________________
Check Out My Site (Still Under Construction) To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||||
|
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
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||||
|
You could always test, next time your computer hangs
![]()
__________________
"C++ is the best programming language in the world. It is perfect. It's fast, efficient, powerful, object oriented, not to mention cool. It's got it all. Except switch-statements on strings..." - marwex89 |
|
|||||
|
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.
__________________
Check Out My Site (Still Under Construction) To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
| Sponsored Links |
|
|
|
|||||
|
Well, if my PC hangs, it won't be able to generate a random number... right?
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||||
|
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.
__________________
Check Out My Site (Still Under Construction) To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||||
|
Ok, what would be an ideal seed?
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||||
|
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.
__________________
Check Out My Site (Still Under Construction) To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||||
|
Quote:
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| filling an array with random #s | gaylo565 | C# Programming | 5 | 05-02-2008 11:21 AM |
| Encryption using Random!? | TcM | Programming Theory | 14 | 01-07-2008 10:48 AM |
| Generating Random Numbers with PHP | Paradine | PHP Tutorials | 4 | 08-27-2007 07:09 PM |
| Return random numbers without duplicates | Paradine | PHP Tutorials | 0 | 08-26-2007 02:07 PM |
| Code:PHP Random Functions | John | PHP Tutorials | 2 | 12-03-2006 10:04 AM |
| Xav | ........ | 1097.16 |
| MeTh0Dz|Reb0rn | ........ | 986.37 |
| morefood2001 | ........ | 850.04 |
| John | ........ | 841.93 |
| WingedPanther | ........ | 684.54 |
| marwex89 | ........ | 638.26 |
| Brandon W | ........ | 492.36 |
| chili5 | ........ | 292.12 |
| orjan | ........ | 187.41 |
| Steve.L | ........ | 183.02 |
Goal: 100,000 Posts
Complete: 79%