Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / "Random Function" question

Author
Message
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 9th Jul 2009 20:44
Hi,,,

Ive been looking at encryption using random numbers, in a similar way to the enigma machine, but I wasnt quite sure how to create a \\\\\\\"random\\\\\\\" function.
I know most languages have a \\\\\\\"random\\\\\\\" function but I dont really know how it works...

Does anyone know and/or explain it? Any help would be much apprectiated.

Thanks,,,

Codeeater
NeX the Fairly Fast Ferret
20
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 9th Jul 2009 20:46
There's no such thing as random on a computer, it's impossible. Instead, a list of 32768 predetermined random binary numbers is cycled through every time rand() is called.

AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 9th Jul 2009 21:33
There's no way to generate a truly random number on a computer. However you could always roll a dice and use the number you get in your program! That way it has to be random!

i like orange
lazerus
17
Years of Service
User Offline
Joined: 30th Apr 2008
Location:
Posted: 9th Jul 2009 21:41
unfortunatly no. well it really depends on the amount of die you roll.

1 is okay, but anymore leads to groupings of number such 7 being the most common rolled number, if i remeber correctly.

Time won’t tell, fate shall’nt decide and the gods themselves can’t intervene for fear of my retrubution. You cannot hide, now face me.
http://lazerusreborn.tumblr.com
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 9th Jul 2009 21:41 Edited at: 10th Jul 2009 00:03
Quote: "it's impossible"


Not entirely.

If you get the systems times milliseconds, which is a number that counts from 0 to 999 in a second, when the user presses a button that he or she was requested to press, I think that that number would be truly random, because you never know when the user will press the button...

And if you don't have that function, you will never know when the user will run the program, right?

TheComet


Make the path of your enemies easier with Waypoint Pro!
AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 9th Jul 2009 21:49
Quote: "because you never know when the user will press the button...
"


You're assuming that an operation is random simply because you don't know it's outcome, but that's wrong.

Quote: "unfortunatly no. well it really depends on the amount of die you roll."


I was kidding...

i like orange
NeX the Fairly Fast Ferret
20
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 9th Jul 2009 21:58
Quote: "milliseconds, which is a number that counts from 0 to 99 in a second"


0 to 999.

Quote: "You're assuming that an operation is random simply because you don't know it's outcome, but that's wrong."


If you used the system time in milliseconds as a seed for rand(), that'd be more than good enough. It'd be very, very random.

AndrewT
18
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 9th Jul 2009 22:01
Quote: "If you used the system time in milliseconds as a seed for rand(), that'd be more than good enough. It'd be very, very random."


Ya, but it wouldn't actually be random.

i like orange
Mr Z
17
Years of Service
User Offline
Joined: 27th Oct 2007
Location:
Posted: 9th Jul 2009 22:01
Quote: "
You're assuming that an operation is random simply because you don't know it's outcome, but that's wrong."


It would be random from a human perspective, because we do not know all factors and because of the issue with free will (unless you believe free will is an illusion, that is). So, basically it would work well enough as a random value.

"Operator! Give me the number for 911!"
- Homer J. Simpson
RiiDii
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 9th Jul 2009 22:26
The problem is that the definition of "random" does not play well with an omniscient philosophy of the universe - that is; one could potentially know everything about everything but we simply do not because we are not nearly advanced enough. Could an omniscient entity ever generate a random number? That's about as likely as an omniscient entity being able to "get lost."

Therefore, the problem isn't so much inherent in what is truly random or not, but rather in our language the defines "random." For example, the word "lost" implies an inability to know enough to know where one is, or perhaps how to arrive at a destination from one's current position. "Lost" infers a limitation on the entity that is "lost". An omniscient being would not be able to adopt the limitation of being "lost" without losing their omniscience.

We can apply these same concepts to "random." Being able to choose something at "random" would infer an applied limitation to omniscience. In conclusion, "random" and "not knowing the outcome" have a lot more in common than not (I am specifically avoiding the phrase "are the same"). From an omniscient perspective, would there be any difference?


Open MMORPG: It's your game!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 9th Jul 2009 22:39
The thing with randomizing seeds, is that you have to be sensible, don't go calling the randomize every loop, try and find something that happens every few seconds instead, maybe a specified particle dies or something like that.

There's also human elements, like the time taken to click a button, or the amount the mouse is actually moving. Sometimes though, it's handy to use the same random seed, like if you have a level that is created randomly, if you use the same seed, you make the same level. It's how Worms managed to have so many different levels.


Health, Ammo, and bacon and eggs!
Grog Grueslayer
Valued Member
20
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 9th Jul 2009 22:45
The lack of a true random number is vital to encrypt/decrypt. To encrypt using a random number you use a specific random seed, create the encryption key, and encrypt. When you want to decrypt you use the same seed, create another encryption key and decrypt. If the seed is the same the decryption key created will be exactly the same and thus work to decrypt properly.



TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 10th Jul 2009 00:05
Quote: "0 to 999."


How embarrassing... I forgot a 9...


Make the path of your enemies easier with Waypoint Pro!
Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 10th Jul 2009 17:24
Ok,,,,, that was a longer discussion than I had at first antisipated :p... When I said "random" I meant appearingly random, and thus I put quotes around it.

I was more looking for just a formula that would produce a "random" number, using the system clock or what ever needed to produce an appearingly random string of numbers, and hopefully and explanation.

Thanks,,,

Codeeater
Grog Grueslayer
Valued Member
20
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Jul 2009 20:17
If you wanted just that why did you talk about encrypting? It's the same as using a random seed except you use something that changes all the time rather than a specific number.



Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Jul 2009 22:00
Maybe I got it the wrong way, but I thought he was asking for an actual algorithm to generate pseudo-random numbers, not for a function that already implements it.

Unfortunately, I don't know any. They are probably rather complex though.

Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 11th Jul 2009 13:49
@Grog

Thanks,,, but as Rudolpho says I am more looking for an algorithm rather than a function. I was actually planning to use it in visual C# any way but thanks for helping.
The encryption thing is to do with random numbers but I was just looking for an algorithm to generate numbers....

Thanks anyway...

Thanks,,,

Codeeater
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 11th Jul 2009 17:59
Quote: "I was actually planning to use it in visual C#"

Surely there must be a random class available?

I understand your interrest in seeing how it works though.

Grog Grueslayer
Valued Member
20
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 11th Jul 2009 19:28
Quote: "Thanks,,, but as Rudolpho says I am more looking for an algorithm rather than a function. I was actually planning to use it in visual C# any way but thanks for helping.
The encryption thing is to do with random numbers but I was just looking for an algorithm to generate numbers....

Thanks anyway...
"


Np. It can still be useful for somebody so I'm not worried about it.

Code eater
17
Years of Service
User Offline
Joined: 17th Feb 2008
Location: Behind You!
Posted: 11th Jul 2009 20:11
Quote: "Surely there must be a random class available?
"


There is...



but I am interested in how it is done like you say...

Thanks,,,

Codeeater
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Jul 2009 20:13
Quote: "I was more looking for just a formula that would produce a "random" number, using the system clock or what ever needed to produce an appearingly random string of numbers, and hopefully and explanation."


I suggest you start here:

Pseudorandom number generator

or, even better, here:

List of pseudorandom number generators

Login to post a reply

Server time is: 2025-05-30 13:29:34
Your offset time is: 2025-05-30 13:29:34