- Joined
- May 9, 2014
- Messages
- 1,820
Hello, reader. This is about coding pseudo-random distribution. I would like to know how to further improve this feature; what are its' pros and cons, so to speak.
Attached is the code for the pseudo-random distribution:
- Zwiebelchen for the table of coefficients..
- The creators of Geogebra for visualizing the graph...
If only I knew to make a table for this...:
If percentage <= 0.5
set new_percentage to (1 - (1 - prev_percentage)*(1 - percentage))
Else
set new_percentage to (1 - prev_percentage)*(1 - percentage)
For real == 0.01
1st - 0.0058...
2nd - 0.0199
3rd - 0.029701
4th - 0.03940399
EDIT:
What joy! I learned how to use hooks. More handles to be cleared to be added.
EDIT 2:
I have learned over the past 6 months that hooks are to be avoided. Rewrote the code to use structs instead.
Made it so that it no longer uses a hashtable.
EDIT 3:
Can be made so that it can still support hashtables. (Request only)
Attached is the code for the pseudo-random distribution:
(x * (1 - x)^(x)) / e ^ ((1 - x)^Sqrt(e))
Credits
JASS:
library PRD
struct PRD
readonly static constant real MAX_POINT = 0.612
readonly static constant real AMPLITUDE = 4/3.
readonly real chance
readonly integer counts
private real base
private boolean absolute
private boolean result
method operator percent takes nothing returns real
return chance
endmethod
method operator percent= takes real perc returns nothing
set absolute = (perc <= 0.) or (perc >= 1.)
if absolute then
set result = (perc >= 1.)
else
set base = perc
// A weird formula that somehow gives me a table suitable for computation...
set chance = AMPLITUDE * (perc * Pow(1 - perc, perc)) / Pow(bj_E, Pow(1 - perc, SquareRoot(bj_E)))
set counts = 0
endif
endmethod
method test takes nothing returns boolean
if absolute then
return result
endif
if (chance * I2R(counts + 1)) >= GetRandomReal(0., 1.) then
set counts = 0
return base <= MAX_POINT
endif
set counts = counts + 1
return base > MAX_POINT
endmethod
static method create takes real perc returns thistype
local thistype this = allocate()
set this.percent = perc
return this
endmethod
endstruct
endlibrary
- Zwiebelchen for the table of coefficients..
- The creators of Geogebra for visualizing the graph...
If percentage <= 0.5
set new_percentage to (1 - (1 - prev_percentage)*(1 - percentage))
Else
set new_percentage to (1 - prev_percentage)*(1 - percentage)
For real == 0.01
1st - 0.0058...
2nd - 0.0199
3rd - 0.029701
4th - 0.03940399
EDIT:
What joy! I learned how to use hooks. More handles to be cleared to be added.
EDIT 2:
I have learned over the past 6 months that hooks are to be avoided. Rewrote the code to use structs instead.
Made it so that it no longer uses a hashtable.
EDIT 3:
Can be made so that it can still support hashtables. (Request only)
Last edited: