Randbetween

tlindeman

Active Member
Joined
Jun 29, 2005
Messages
313
I know how to use Randbetween, however is there any way to generate a random number between using a dataset? My low is 9.41 and my high is 19.68 and Randbetween only generates integers (whole numbers) I am open to VBA if someone can provide the code.

Thank You
Tony
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I like HotPepper's solution, but I don't think the '+1' is necessary. If you look at the two extreme cases where Rand() generates a 0 or 1, the the results should be the ends of the range. Therefore, just modify to

(B2-A2)*Rand()+A2
 
Upvote 0
Rand will never generate a 1 on its own.

It returns an evenly distributed random real number greater than or equal to 0 and less than 1
 
Upvote 0
HotPepper - You are definitely correct that it will not generate a 1. However, the '+1' still isn't needed as illustrated:

=(19.68 - 9.41 +1) * Rand() + 9.41

Rand() Answer
0 9.41
.25 12.22
.50 15.05
.75 17.86
.95 20.12

In this scenario, any number generated by Rand() that is greater than .911 will give an answer outside the range, ie greater than 19.68.
 
Upvote 0
You're right, usually you use the +1, if it is used with INT to generate whole numbers in a range.
 
Upvote 0
Thanks for the acknowledgement, but you did all the work on the solution. It is much easier to heckle from the crowd than be on stage. Maybe we should just call it good teamwork!
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top