# Thread: Random Number Generation and Rational Reliability

1. ## Random Number Generation and Rational Reliability

User Reginal (MMcNaughton@STSSystems.com) posted:

The problem with this is that you will always receive the same numbers
everytime you call it.

Run it and you'll get:
1
2
8
5
6
3
1
7
7
10

So that everytime you run it you'll never really get a 'random' number.

It needs to be 'seeded'. To do this you need to use Randomize and the
online help suggest the timer() to get a value and it is good since it
changes every second.

2. ## Re: Random Number Generation and Rational Reliability

User Tom Ba (tombasay@hotmail.com) posted:

Max is sooo right.:-)

Why go crazy unless
you're going to go all the way.

Time to break out the PaulBDownes
whacked-as-all-get-out boson counter...
for when what you want is irreproducibility
at its finest.

Declare Function QueryPerformanceCounter Lib "kernel32.dll" (lCounts as
long) as long

Declare Function GetSeed()

Sub Main

dim upper as integer
dim lower as integer
dim iVal as integer
dim iRandomvalue as integer
dim sLetter as string
dim x as integer

upper = 10
lower = 1

iVal = GetSeed()

Randomize iVal

For x = 1 to 10
irandomvalue=Int((upper - lower + 1) * Rnd +lower)
msgbox "My expected result is " & iRandomValue
Next x

End Sub
'################################################# ###########################
'#
'# Function GetSeed()
'#
'# DESCRIPTION:
'#
'# When called, this function returns a seed value between
'# somewheres between -32,768 and 32,767, which are the limits for
input to the
'# SQA Basic Randomize function. The randomize function
'# seeds the random number generator as described below
'#
'# Randomize [number% ]
'#
'# where
'# number% An integer value between -32768 and 32767.
'#
'#
'# Modified to use queryperformanceCounter, which returns the number of
'# falling grains of sand in the Great Egg Timer of Eternity,
'# thus ensuring the integrity of the unique whackiness.
'#
'# Thanks be to P. Downes.
'#
'# ARGUMENTS: none
'#
'# RETURNS: Unique integer value between approximately -32000 and 32000,
'# is anyone really counting?
'#
'# EXAMPLES: Result = GetSeed
'#
'#
'# ERRORS:
'#
'# none
'#
'# Orig Author: Tom Swain
'# Orig Date: JAN 29, 2001
'# History:
'#
'# JAN 29, 2001 Original Release
'# JAN 30, 2001 Modified to use queryPerformance Counter
'#
'################################################# ###########################

Function GetSeed() as integer
dim s2 as string
dim s1 as string
dim ival as integer
dim m1 As Long
dim lValue as long
dim rc as long

rc = QueryPerformanceCounter(m1)

'Values returned from the above
'm1&: 776679940

'convert to a string
s1 = cstr(m1)

'get the last five characters (1-99999)
s2 = right(s1,5)

'The following ensures that the largest integer value is approximately
32767*2 or 65534
lValue = (clng(s2) ) /1.525910

If lValue > 32767 then
iVal = 65534 - int(lValue)
else
iVal = -32767 + int(lValue)
end if

GetSeed = iVal

End Function

<<<<<<<<<<<<<<<

----Original Message Follows----
From: MMcNaughton@STSSystems.com
Reply-To: "SQA Suite Team Test Users" <sqa-suite-users@lyris.dundee.net>
To: "SQA Suite Team Test Users" <sqa-suite-users@lyris.dundee.net>
Subject: RE: Random Number Generation and Rational Reliability
Date: Tue, 17 Jul 2001 13:18:34 -0400

The problem with this is that you will always receive the same numbers
everytime you call it.

Run it and you'll get:
1
2
8
5
6
3
1
7
7
10

So that everytime you run it you'll never really get a 'random' number.

It needs to be 'seeded'. To do this you need to use Randomize and the
online help suggest the timer() to get a value and it is good since it
changes every second.

3. ## Re: Random Number Generation and Rational Reliability

User (MMcNaughton@STSSystems.com) posted:
Tomba cranky today, the neighbors haven't forgiven you for the flooding
yet?! ;o)

4. ## Re: Random Number Generation and Rational Reliability

User MArk B. (mkbutler@russellmellon.com) posted:

The fluids are gone but the scent lingers...

MArk B.
Where's the energizer bunny when you need him?
---

5. ## Re: Random Number Generation and Rational Reliability

User Tom Ba (tombasay@hotmail.com) posted:

Hey!

When you're generating as much spurious data as I do,
to replicate Rational's results,
this is the function to have.

Tomba Septic Service

It may be *(@#&* to you,
but it's our bread and butter
----Original Message Follows----
From: MMcNaughton@STSSystems.com
Reply-To: "SQA Suite Team Test Users" <sqa-suite-users@lyris.dundee.net>
To: "SQA Suite Team Test Users" <sqa-suite-users@lyris.dundee.net>
Subject: RE: Random Number Generation and Rational Reliability
Date: Tue, 17 Jul 2001 14:49:25 -0400

That's what that stupid looking empty loop was for, Paul's is of course
supreme. What exactly did he need that for, all combinations of credit card
numbers?? Mine was a quickly needed to generate data that i wasn't set up
to have, it actually was nice that some dates were repeated and some prices,
sale a day ) can't get enough merchandise needing to be \$9.99 either.

You'd have been crankier if you'd been on the front yard at the time!!!
)=)

Max
What is that smell, oh it's Tomba, don't ask

__________________________________________________ _______________

6. ## Re: Random Number Generation and Rational Reliability

User (MMcNaughton@STSSystems.com) posted:

oooo just reread that, just to clarify i was refering to MY stupid little
loop btw:

For y = 1 to 1500
Next y

And Paul's fabulous alternative.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.