ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Upper and Lower Bounds and Rnd (https://www.excelbanter.com/excel-programming/287298-upper-lower-bounds-rnd.html)

[email protected]

Upper and Lower Bounds and Rnd
 
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

mudraker[_83_]

Upper and Lower Bounds and Rnd
 
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

--
Message posted from http://www.ExcelForum.com


Henry[_5_]

Upper and Lower Bounds and Rnd
 
Terry,

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

HTH
Henry

wrote in message
om...
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




Bob Phillips[_6_]

Upper and Lower Bounds and Rnd
 
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)

wrote in message
om...
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





All times are GMT +1. The time now is 11:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com