Hi all here.
I am trying to write a procedure which accepts a math function or any other kind of data to tell to the procedure the zone (in the real rect) in which the random generator must generate results with more or less probabilities.
In other words, i explain:
Random() native PB function is able to generate numbers (scalars) inside a defined section in the real rect. But:
How to generate it inside the the same section but given a curve (math function -for example Gauss function- ) where the generated numbers are most probable there where the curve is higher and less probable there where the curve is lower?
Thanks in advance!
How to generate random values in probable zones
- Psychophanta
- Addict
- Posts: 4996
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
How to generate random values in probable zones
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
Re: How to generate random values in probable zones
Perhaps over natural logarithm
Code: Select all
Dim c(100)
Define r.f
For i = 1 To 100000
r = Random(1700) * 0.001 + 1.0
v = Log(r) * 100
c(v) + 1
Next
For i = 0 To 100
Debug "Count of " + i + " = " + c(i)
Next
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: How to generate random values in probable zones
sounds like you want a PDF
https://en.wikipedia.org/wiki/Probabili ... y_function
https://en.wikipedia.org/wiki/Probabili ... y_function
Windows 11, Manjaro, Raspberry Pi OS
Re: How to generate random values in probable zones
here are also two procedure for random numbers with Gaussian or Cauchy distribution.
The transformation rule (for any distributions) is, you have to integrate your function, build the inverse function of it, and than you can apply it on Random().
Function: Cauchy(x) = 1/pi * s/(s^2+x^2)
Integral: 0.5 + arcTan(x/s)/pi
Inverse: -s * cot(pi*x) or s*tan(pi*x) if you cange the definition range of x
Code: Select all
Procedure.f RandomGaussian(Width.f=1.0)
Protected X.f = 9.3132257461547851563e-10 * (Random(2147483646)-1073741823)
Protected Ln.f = Log(1-X*X)*0.5
ProcedureReturn Sign(X)*Sqr(Sqr((4.546884979448284327+Ln)*(4.546884979448284327+Ln)-Ln*14.28446044815250805)-4.546884979448284327-Ln)*Width
EndProcedure
Procedure.f RandomCauchy(Width.f=1.0)
Protected X.f = 9.3132257461547851563e-10 * (Random(2147483646)-1073741823)
ProcedureReturn Tan(#PI*X)*Width
EndProcedure
Function: Cauchy(x) = 1/pi * s/(s^2+x^2)
Integral: 0.5 + arcTan(x/s)/pi
Inverse: -s * cot(pi*x) or s*tan(pi*x) if you cange the definition range of x
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
- Psychophanta
- Addict
- Posts: 4996
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Lípetsk, Russian Federation
- Contact:
Re: How to generate random values in probable zones
Thank you all.
I guess with your points i'll have the idea to build some nice approaches and then a good solid procedure for it.
I guess with your points i'll have the idea to build some nice approaches and then a good solid procedure for it.
http://www.zeitgeistmovie.com
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB
While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB