Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-21-2008, 09:09 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,263
Credits: 0
Rep Power: 74
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Random.. not actually random

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?
__________________

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-21-2008, 12:33 PM
MeTh0Dz|Reb0rn's Avatar   
MeTh0Dz|Reb0rn MeTh0Dz|Reb0rn is offline
Guru
 
Join Date: Jul 2008
Posts: 1,467
Credits: 986
Rep Power: 13
MeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the rough
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.
__________________
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-21-2008, 12:50 PM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,263
Credits: 0
Rep Power: 74
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: Random.. not actually random

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-21-2008, 12:55 PM
marwex89's Avatar   
marwex89 marwex89 is offline
Guru
 
Join Date: Jul 2008
Location: Viking-land!
Posts: 2,421
Credits: 638
Rep Power: 19
marwex89 has a spectacular aura aboutmarwex89 has a spectacular aura aboutmarwex89 has a spectacular aura about
Send a message via AIM to marwex89
Default Re: Random.. not actually random

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-21-2008, 01:00 PM
MeTh0Dz|Reb0rn's Avatar   
MeTh0Dz|Reb0rn MeTh0Dz|Reb0rn is offline
Guru
 
Join Date: Jul 2008
Posts: 1,467
Credits: 986
Rep Power: 13
MeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the rough
Default Re: Random.. not actually random

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 07-21-2008, 01:25 PM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,263
Credits: 0
Rep Power: 74
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: Random.. not actually random

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-21-2008, 01:39 PM
MeTh0Dz|Reb0rn's Avatar   
MeTh0Dz|Reb0rn MeTh0Dz|Reb0rn is offline
Guru
 
Join Date: Jul 2008
Posts: 1,467
Credits: 986
Rep Power: 13
MeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the rough
Default Re: Random.. not actually random

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-21-2008, 01:44 PM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,263
Credits: 0
Rep Power: 74
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: Random.. not actually random

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-21-2008, 01:50 PM
MeTh0Dz|Reb0rn's Avatar   
MeTh0Dz|Reb0rn MeTh0Dz|Reb0rn is offline
Guru
 
Join Date: Jul 2008
Posts: 1,467
Credits: 986
Rep Power: 13
MeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the roughMeTh0Dz|Reb0rn is a jewel in the rough
Default Re: Random.. not actually random

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-21-2008, 02:57 PM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 8,263
Credits: 0
Rep Power: 74
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default Re: Random.. not actually random

Quote:
polymorphism
What's that?
__________________

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -5. The time now is 11:19 PM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads