Programming question

Video Game Discussions and general topics.

Moderators: AArdvark, Ice Cream Jonsey

User avatar
Ice Cream Jonsey
Posts: 28923
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Programming question

Post by Ice Cream Jonsey »

You want something to happen one out of a thousand times.

Would you do this:

foobar = random(10000)
if foobar > 9990

Or this?

foobar = random(1000)
if foobar =1000
the dark and gritty...Ice Cream Jonsey!

User avatar
Flack
Posts: 8832
Joined: Tue Nov 18, 2008 3:02 pm
Location: Oklahoma
Contact:

Post by Flack »

Statistically I think they're the same. I assume the second (1/1000) requires less cycles, but not possibly enough to make a difference in modern systems.
"I failed a savings throw and now I am back."

User avatar
pinback
Posts: 17700
Joined: Sat Apr 27, 2002 3:00 pm
Contact:

Post by pinback »

foobar = random(1000)
if foobar = 69

huhhhuhu

EDIT: In most languages "if foobar = 1000", as you had it, wouldn't work, because in most languages "random(1000)" would return a number from 0 to 999.
I don't have to say anything. I'm a doctor, too.

User avatar
Ice Cream Jonsey
Posts: 28923
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

pinback wrote:foobar = random(1000)
if foobar = 69

huhhhuhu

EDIT: In most languages "if foobar = 1000", as you had it, wouldn't work, because in most languages "random(1000)" would return a number from 0 to 999.
Thanks. Not in Hugo it doesn't, Hugo is smart enough to interpret that how I wrote it, and that was what I was writing in before HURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
the dark and gritty...Ice Cream Jonsey!

User avatar
RealNC
Posts: 2246
Joined: Wed Mar 07, 2012 4:32 am

Post by RealNC »

I prefer floating point for this, just so I can write "0.1" to mean 0.1%. Too bad Hugo doesn't have FP.

Wouldn't it fun to do Bitcoin mining in Hugo? :P

Post Reply