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 / Stupid rnd() keeps giving different values!

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Mar 2013 01:43
Found this just now, gave me a good chuckle.



"You're all wrong. You're all idiots." ~Fluffy Rabbit
Dark Java Dude 64
Community Leader
15
Years of Service
User Offline
Joined: 21st Sep 2010
Location: Neither here nor there nor anywhere
Posted: 11th Mar 2013 03:12
I can't seem to get this program to work...



It always prints 0, and I don't know why!
Jeku
Moderator
23
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Vancouver, British Columbia, Canada
Posted: 11th Mar 2013 05:23
Actually that question makes sense. If you don't seed the randomizer first, then it shouldn't give a different value everytime.


Senior Developer - CBS Interactive Music Group
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 11th Mar 2013 14:19
I saw this somewhere else:


Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!
RedFlames
18
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 11th Mar 2013 14:34
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Mar 2013 18:31
You have a point Jeku. I guess the joke is on us then!

"You're all wrong. You're all idiots." ~Fluffy Rabbit
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 11th Mar 2013 22:46
does he recived an answer on this question?

Advanced Updater for your games!
Yodaman Jer
User Banned
Posted: 11th Mar 2013 23:32
Quote: "If you don't seed the randomizer first, then it shouldn't give a different value everytime."


Then why even use Rnd() if you want the same number every time? Wouldn't a constant be better in that case?

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 12th Mar 2013 00:18
He does say 'values', so he's polling the RND() function and expecting the same sequence. If the seed is initialized differently each time the code executes, he'll get a different sequence of values.

bitJericho
23
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 12th Mar 2013 03:22
Quote: "Then why even use Rnd() if you want the same number every time? Wouldn't a constant be better in that case?"


I could think of lots of reasons. Dynamic levels that stay the same each play. Dynamic textures that you want to look the same. I could go on.

Visit my blog http://www.canales.me.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Mar 2013 10:05
Without a predictable series of RND values, games like Elite would take up megabytes instead of kilobytes. Games like Worms, Minecraft, Terraria all work using a seed number, which is basically just a random seed like we would set with the RANDOMIZE command - then the terrain is generated randomly based on that seed, and using the same seed each time guarantee's the same outcome.

Imagine you were making a space game, and want a random universe, maybe handling each solar system separately. What you could do is just give each solar system a number, even just coordinates from a map - create a seed number from the coordinates, then randomize a name, number of planets, planet texture and properties, position in sun orbit, right down to the position of moons and asteroids. If you can generate that based on a simple seed, then that's all memory that doesn't have to be permanent - you could just explore each solar system, warp between them, and your game could be exponentially huge, infinitely huge if you like.

In Worms, the level seed generates a whole level, and that level would probably take a few megabytes to store permanently - instead it takes up about 4 bytes, in fact it doesn't - but if you wanted to reproduce a specific level, you would use a specific seed number.

I got a fever, and the only prescription, is more memes.
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 12th Mar 2013 11:02
Quote: "Quote: "If you don't seed the randomizer first, then it shouldn't give a different value everytime."

Then why even use Rnd() if you want the same number every time? Wouldn't a constant be better in that case?"



If they want to use the same random number elsewhere it might make sense. I've done it with some of my RPG battle calculations. Though, the solution is to just store the rnd into a variable and not update with a rnd every loop.

RUCCUS
21
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 12th Mar 2013 16:55
@Seppuku

That'd only work for a single running of the application, the number would be different every time it is run unless you were to save the stored random number which kind of defeats the purpose.
Yodaman Jer
User Banned
Posted: 12th Mar 2013 22:00
@Jericho and Van B:

Ah, ok, I hadn't thought of it like that. Good points!

Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 12th Mar 2013 22:20 Edited at: 12th Mar 2013 22:21
Quote: "@Seppuku

That'd only work for a single running of the application, the number would be different every time it is run unless you were to save the stored random number which kind of defeats the purpose. "


For the situation I was referring, it's random every time I call the method 'CalculateDamage()', which gives a return value based on an a few equations using 'rnd' in places, which I then store temporarily. So it's calling the 'rnd' once in the calculations, taking it away, using it to decrease the enemy's health and also display the damage on screen for a few seconds. So, yes, it is for a single running of the application, heck it probably only last for a few seconds, depending on when the player attacks again.

So I would say it's an example of where I don't want my 'rnd' value to keep changing, as I'm reusing that value.

An example of the kind of calculation I'm talking about. Taken from my blog as I don't have the project (with the improvements to make it more modular) on this PC yet.


Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Mar 2013 14:49
In the case of this ASP snippet, he isn't specifying a seed value. Therefore every time he calls the function it's returning the next random value in the sequence.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Mar 2013 09:08
Quote: "Therefore every time he calls the function it's returning the next random value in the sequence."

this

*** Merry Chuckmas! ***

Login to post a reply

Server time is: 2026-07-16 00:30:53
Your offset time is: 2026-07-16 00:30:53