Solved

random numbers stay in "memory"

Posted on 2000-03-17
3
192 Views
Last Modified: 2010-05-02
I wrote a simple applications that should generate random numbers between 1 and 49. All works
nice, but if I close the app and run it again, the same numbers are generated when I ran it first ( If I
keep genrating numbers, they appear to be random, but the same series pops back each time I run
the app)
I get the feeling that these numbers are kept somewhere. Even if I restart the PC, these series stay
the same. I don't save these generated numbers to disk, I just display them on a form ( as the
text.text)
Is there a function I should use to "flush" the memory or something???



Private Sub Command1_Click()
    Dim no1, no2, no3, no4, no5, no6 As Integer

complete1 = False
Do While complete1 = False
    no1 = Round(Rnd * 100)
    If no1 <= 49 And no1 > 0 Then
    complete1 = True
    End If
Loop
Text1.Text = no1

complete2 = False
Do While complete2 = False
    no2 = Round(Rnd * 100)
    If no2 <= 49 And no2 > 0 And no2 <> no1 Then
    complete2 = True
    End If
Loop
Text2.Text = no2

complete3 = False
Do While complete3 = False
    no3 = Round(Rnd * 100)
    If no3 <= 49 And no3 > 0 And no3 <> no2 And no3 <> no1 Then
    complete3 = True
    End If
Loop
Text3.Text = no3

complete4 = False
Do While complete4 = False
    no4 = Round(Rnd * 100)
    If no4 <= 49 And no4 > 0 And no4 <> no3 And no4 <> no2 And no4 <> no1 Then
    complete4 = True
    End If
Loop
Text4.Text = no4

complete5 = False
Do While complete5 = False
    no5 = Round(Rnd * 100)
    If no5 <= 49 And no5 > 0 And no5 <> no4 And no5 <> no3 And no5 <> no2 And no5 <> no1 Then
    complete5 = True
    End If
Loop
Text5.Text = no5

complete6 = False
Do While complete6 = False
    no6 = Round(Rnd * 100)
    If no6 <= 49 And no6 > 0 And no6 <> no5 And no6 <> no4 And no6 <> no3 And no6 <> no2 And
no6 <> no1 Then
    complete6 = True
    End If
Loop
Text6.Text = no6
End Sub

0
Comment
Question by:psimation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Accepted Solution

by:
ture earned 50 total points
ID: 2628681
Add this at the beginning of your procedure:

Randomize(Timer)

Ture Magnusson
Karlstad, Sweden
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2628709
Ture is correct, you need to use the Randomize statement, however "Randomize(Timer)" is redundant.

All you really need to do is:

   Randomize

Directly from VB help page on Randomize:

"Randomize uses number to initialize the Rnd function's random-number generator, giving it a new seed value. If you omit number, the value returned by the system timer is used as the new seed value."


Cheers!®©
0
 
LVL 17

Author Comment

by:psimation
ID: 2628750
Thanks, works like a charm.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 92
VBA/SQL - Connect to SQL server and pull data 4 137
Excel - Save a copy of work book 13 91
pop out of webbrowser1 control vba6 5 44
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question