• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

[JASS] GetRandomReal

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2010
Messages
230
GetRandomReal(1.,100.) == 1.
GetRandomReal(1.,100.) == 1
GetRandomReal(1.,100.) <= 1.01
what is the chance of these happening?
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,226
Hard to say.. in GUI reals can only have 2 decimals so it's somewhat easy to calculate. Reals in jass can be pretty long though 8 decimals or something.

However I doubt GetRandomReal() uses 8 decimals when getting a random real..



assuming it's 2 decimals
GetRandomReal(1.,100.) == 1.
GetRandomReal(1.,100.) == 1
GetRandomReal(1.,100.) <= 1.01

0,01%
0.01%
0.011%

because 1. and 1 is the same thing right? or is 1. = 1.x?
 
You should either truncate reals or use < and > to define a result range.

I don't know what the precision on GetRandomReal is, so depending on that, a perfect equal might happen between 0.01% (for 2 decimals after comma) and 0.00000001% (for 8 decimals after comma).

but does GetRandomReal(1,100) generetes 0.00 to 0.99?
It generates between 1.00 and 100.00. So no, 0.00 and 0.99 can never happen.
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
All the stuff about the decimals of a real is just plain wrong. Especially Chaosy, who started all this.

Wc3 uses IEEE 754 single-precision binary floating-point format, or something very similar.

There are no GUI-reals and JASS-reals, it's all the same. Whenever you deal with reals the game converts your input to the closest real that can actually be represented in the format.

@OP: The chance for your conditions to be true are extremely small.
If you want to represent some percentage chance, just use GetRandomInt.
 
Level 6
Joined
Aug 12, 2010
Messages
230
so basically i guess the question is..whats the binary counterpart of "1" and how many binary reals are there (1,100)
 
so basically i guess the question is..whats the binary counterpart of "1" and how many binary reals are there (1,100)
Do you even understand what you are trying to achieve?
If you want to code a custom droplist, there's no need to use '='. Just just use '<' or '>'.


So, for example, if you want stuff to happen at a 1% chance, just use this:
if GetRandomReal(0,100) < 1. then
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
so this is false?
Yes, the chance for (GetRandomReal(1.,100.) <= 1.01) to be true is much much less than 1%.

so basically i guess the question is..whats the binary counterpart of "1" and how many binary reals are there (1,100)
Do you want to make some percentage chance calculation out of my answer or what do you want actually?

If yes, as already advised, you should not do that and use GetRandomInt because we can't be sure how reals are handled exactly internally.
If you end up using something like GetRandomReal(1,1.022134211)<1.012412422 you deserve to be slapped with a trout :grin:
 
Status
Not open for further replies.
Top