VBA codes for Random Number Generator - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# VBA codes for Random Number Generator

Posts: 3Member
Hi,

Someone sent me this codes. Is it VBA codes ?
Is it for random number generator ?

[italic][b]Public i97, j97, u(97) As Double, c As Double, cd As Double, cm As Double, uni As Double
Public Sub Init()
Dim i, ii, j, k, ij, kl, l, m, jj, ivec, i5, j5, s As Double, t As Double
ij = Seed1
kl = Seed2
i = ((ij / 177) Mod 177) + 2
j = (ij Mod 177) + 2
k = ((kl / 169) Mod 178) + 1
l = kl Mod 169
For ii= 1 To 97
s = 0#
t = 0.5
For jj = 1 To 24
m = ((i * j Mod 179) * k) Mod 179
i = j
j = k
k = m
l = (53 * l + 1) Mod 169
If ((l * m) Mod 64) >= 32 Then s = s + t
t = 0.5 * t
Next
u(ii) = s
Next
c = 362436# / 16777216#
cd = 7654321# / 16777216#
cm = 16777213# / 16777216#
i97 = 97
j97 = 33
End Sub

Public Function RND() as Double
uni = u(i97) - u(j97)
If uni < 0# Then uni = uni + 1#
u(i97) = uni
i97 = i97 - 1
If i97 = 0 Then i97 = 97
j97 = j97 - 1
If j97 = 0 Then j97 = 97
c = c - cd
If c < 0# Then c = c + cm
uni = uni - c
If (uni < 0#) Then uni = uni + 1#
RND=uni
end Function[/b][/italic]

Regards

James