Solved

get different random number when program stop and start again

Posted on 2006-07-18
5
148 Views
Last Modified: 2010-04-30
hi,
I want to find a random number within a range (between max and min number). I use the following function like below.

c = minCol1 + Int(Rnd() * (maxCol1 - minCol1))

I found that this random number always show same number.  for example:

first time show 12
second time show 18
third time shows 36

when I stop the program. and then start the program again. the random number start from 12, 18, 36.  it seems random number always stay same order....

is there anyway to have random number not always different even I stop and restart the program. thank you!




0
Comment
Question by:rmtogether
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
Randomize
c = minCol1 + Int(Rnd() * (maxCol1 - minCol1))
0
 

Author Comment

by:rmtogether
Comment Utility
hi, jimhorn

this is samething I use. but If you get random number like 3,9,5,3,63,5,6......and so on then you stop program.

when you run program again the random number you get would be 3,9,5,3,63,5,6 .....and so on. this is same with the first time when you start program.

Is it possible to have differece sequence of random numbers. after you restart program

thanks
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
In your code, type the keyword 'Randomize' immeately above your c+ line, save, run again.
0
 

Author Comment

by:rmtogether
Comment Utility
hi, Jimhorn

yes, I put 'Randomize' , the result is different. thanks I got it
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
Thanks for the grade.  Good luck with your project.  -Jim

p.s. I built a screen saver five years ago in VB that used Rnd() to establish the direction and speed of pool balls moving across the screen.  For awhile, I couldn't figure out why each ball started in the same position, with the same direction and speed, until I added Randomize.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now