Post Reply 
New Appoach for Random Number Generation???
03-21-2019, 07:51 PM (This post was last modified: 03-21-2019 07:52 PM by Namir.)
Post: #6
RE: New Appoach for Random Number Generation???
Here is another example, this time using two Calculator-oriented PRNGs! This is somewhat ironic :-)

Code:
Option Explicit

Function Frac(ByVal x As Double) As Double
  Frac = x - Fix(x)
End Function

Function Rnd1(ByVal x As Double) As Double
  Rnd1 = Frac(997 * x)
End Function

Function Rnd2(ByVal x As Double) As Double
  Dim Pi As Double
  Pi = 4 * Atn(1)
  Rnd2 = Frac(Pi + x) ^ 3
End Function

Function Rand12(ByVal x As Double) As Double
  Dim Diff As Double
  Dim L As Integer
  
  Diff = Abs(Rnd1(x) - Rnd2(x))
  L = Fix(Log(Diff) / Log(10))
  x = Diff / 10 ^ L
  x = Frac(10000 * x)
  Rand12 = x
End Function

Sub go()
  Const max = 10000
  Dim x As Double
  Dim I As Integer
  
  Randomize Timer
  x = Rnd(1)
  For I = 1 To max
    DoEvents
    x = Rand12(x)
    Cells(I, 1) = x
  Next I
End Sub

Again, the ideas is to get the numerical noise out of low decimal places.

Namir

Heretic Math Hobbyist
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: New Appoach for Random Number Generation??? - Namir - 03-21-2019 07:51 PM



User(s) browsing this thread: