Upper and Lower Bounds and Rnd

  • Thread starter terryspencer2003
  • Start date
T

terryspencer2003

I have been using the following formula to generate a random number
between 1 and 42. I have made my UpperBounds = 42 and my LowerBounds
= 1. I ran 1,000 iterations and in several instances, the random
number generated equaled 43. How is this? Is there an error in my
logic?

RandomNumber = Int((UpperBounds - LowerBounds) + 1)* Rnd + LowerBounds

TS
 
M

mudraker

I have not used a random number generator but if I understand i
correctly

you are adding 1 to what ever RND number generates which could be an
number from 1 to 42

Which means that you will never have a 1 but can have a 4
 
H

Henry

Terry,

Try
RandomNumber = Int((UpperBounds - LowerBounds + 1)* Rnd) + LowerBounds

HTH
Henry
 
B

Bob Phillips

Try this

RandomNumber = Int(Rnd * (upperbounds - lowerbounds + 1)) + lowerbounds


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top