• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

get different random number when program stop and start again

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
rmtogether
Asked:
rmtogether
  • 3
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Randomize
c = minCol1 + Int(Rnd() * (maxCol1 - minCol1))
0
 
rmtogetherAuthor Commented:
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
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
In your code, type the keyword 'Randomize' immeately above your c+ line, save, run again.
0
 
rmtogetherAuthor Commented:
hi, Jimhorn

yes, I put 'Randomize' , the result is different. thanks I got it
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now