MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 1st, 2002, 08:45 AM   #1
eliW
Board Regular
 
eliW's Avatar
 
Join Date: Mar 2002
Posts: 1,805
Default

On 30/3 Chris Davison posted a question in:
http://www.mrexcel.com/board/viewtop...orum=2&start=0

Quote:
Evening all,
how can I return a single random number from the set : 1 to 10 and 20 to 30

ie

8 would be okay
2 would be okay
23 would be okay
29 would be okay

but 15 would not be okay
and 18 would not be okay

Just one random number from those ranges 1-10, 20-30
It was answered by using a single formula.

Now how can it be done for 3 ranges of numbers, say: 1-10, 21-30, 51-60, in one single formula?

Eli


[ This Message was edited by: eliW on 2002-04-01 07:49 ]
eliW is offline   Reply With Quote
Old Apr 1st, 2002, 08:52 AM   #2
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Hi Eli,

I forgot to thank you for that, my apologies

I liked the way you'd split the randomness into the size of the population and then "if"d it accordingly on the proportion of the split in the whole population 40:60 (or whatever it was)... very clever

maybe with 3 ranges of sizes 10:15:8 (or whatever) you can apply the same logic and incorporate an appropriate number of nested IFs ?



edit : I'd be tempted to not make the ranges equal in size though, it forces us to think of proper random samples (my original question was just a fluke of equal sizes, I hadn't meant it to be)

[ This Message was edited by: Chris Davison on 2002-04-01 07:57 ]

[ This Message was edited by: Chris Davison on 2002-04-01 08:00 ]
Chris Davison is offline   Reply With Quote
Old Apr 1st, 2002, 09:18 AM   #3
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Quote:
On 2002-04-01 07:45, eliW wrote:
On 30/3 Chris Davison posted a question in:
http://www.mrexcel.com/board/viewtop...orum=2&start=0

Quote:
Evening all,
how can I return a single random number from the set : 1 to 10 and 20 to 30

ie

8 would be okay
2 would be okay
23 would be okay
29 would be okay

but 15 would not be okay
and 18 would not be okay

Just one random number from those ranges 1-10, 20-30
It was answered by using a single formula.

Now how can it be done for 3 ranges of numbers, say: 1-10, 21-30, 51-60, in one single formula?

Eli


[ This Message was edited by: eliW on 2002-04-01 07:49 ]
Hi Eli,

For up to 30 (?) different ranges, use the CHOOSE function, with the index as a randbetween (like your very nice example with two ranges).

=CHOOSE(RANDBETWEEN(1,3),RANDBETWEEN(1,10),RANDBETWEEN(21,30),RANDBETWEEN(51,60))

Gotta run now, but I will work on the unequal sized ranges when I get time.

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 1st, 2002, 09:18 AM   #4
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

consider the following (unequal) populations :

1) 2 to 8
2) 15 to 23
3) 44 to 100

7, 9 and 57 numbers respectively, total population of 73 numbers

so take a random number between 0 and 72

if it's =<6 then take a random number between 2 and 8

if it's between 7 and 15 then take a random number between 15 and 23

if it's =>16 then take a random number between 44 and 100

would this work, statistically ?

[ This Message was edited by: Chris Davison on 2002-04-01 08:20 ]

[ This Message was edited by: Chris Davison on 2002-04-01 08:21 ]
Chris Davison is offline   Reply With Quote
Old Apr 1st, 2002, 09:30 AM   #5
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,314
Default

On 2002-04-01 07:45, eliW wrote:
On 30/3 Chris Davison posted a question in:
http://www.mrexcel.com/board/viewtop...orum=2&start=0


Evening all,
how can I return a single random number from the set : 1 to 10 and 20 to 30

ie

8 would be okay
2 would be okay
23 would be okay
29 would be okay

but 15 would not be okay
and 18 would not be okay

Just one random number from those ranges 1-10, 20-30
[/font]

It was answered by using a single formula.

Now how can it be done for 3 ranges of numbers, say: 1-10, 21-30, 51-60, in one single formula?


Eli,

How about:

=EVAL(VLOOKUP(RANDBETWEEN(1,3),{1,"RANDBETWEEN(1,10)";2,"RANDBETWEEN(21,30)";3,"RANDBETWEEN(51,60)"},2,0))

where I use EVAL, a UDF by Longre?

Aladin
Aladin Akyurek is offline   Reply With Quote
Old Apr 1st, 2002, 09:55 AM   #6
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

that's nice Aladin..... my IF logic falls down at the first hurdle where the first ELSE arguement comes into play..... it can't be referenced back to the original =RAND function with more than 2 possibilities
Chris Davison is offline   Reply With Quote
Old Apr 1st, 2002, 03:44 PM   #7
eliW
Board Regular
 
eliW's Avatar
 
Join Date: Mar 2002
Posts: 1,805
Default

Thank you guys for your sophisticated answers:

Aladin suggested using VLOOKUP function combined with UDF:

Quote:
=EVAL(VLOOKUP(RANDBETWEEN(1,3),{1,"RANDBETWEEN(1,10)";2,"RANDBETWEEN(21,30)";3,"RANDBETWEEN(51,60)"},2,0))

where I use EVAL, a UDF by Longre?
Aladin
That would solve the problem of multiconditional random as Chris wrote later:

Quote:
"that's nice Aladin..... my IF logic falls down at the first hurdle where the first ELSE arguement comes into play..... it can't be referenced back to the original =RAND function with more than 2 possibilities"
It is really nice but can be done in simpler way by IF function only:

=IF(RANDBETWEEN(0,2)=0,RANDBETWEEN(1,10),IF(RANDBETWEEN(0,1)=0,RANDBETWEEN(21,30),RANDBETWEEN(51,60)))

This approach can be used with some changes also to different size ranges.

Thank you all,
Eli



[ This Message was edited by: eliW on 2002-04-01 14:47 ]
eliW is offline   Reply With Quote
Old Apr 1st, 2002, 04:02 PM   #8
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Nice work Eli, again.

I missed the ELSE logic.... you don't need to refer back, you just recalc again on 0 or 1....hotdamn

I suppose the extent to which this can be extrapolated (using known population sizes) is only limited by the maximum number of nested IFs allowable.

Chris Davison is offline   Reply With Quote
Old Apr 1st, 2002, 07:17 PM   #9
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Quote:
On 2002-04-01 08:18, Chris Davison wrote:
consider the following (unequal) populations :

1) 2 to 8
2) 15 to 23
3) 44 to 100

7, 9 and 57 numbers respectively, total population of 73 numbers

so take a random number between 0 and 72

if it's =<6 then take a random number between 2 and 8

if it's between 7 and 15 then take a random number between 15 and 23

if it's =>16 then take a random number between 44 and 100

would this work, statistically ?

[ This Message was edited by: Chris Davison on 2002-04-01 08:20 ]

[ This Message was edited by: Chris Davison on 2002-04-01 08:21 ]
Hi Chris,

=IF(RANDBETWEEN(1,73)>16,RANDBETWEEN(44,100),IF(RANDBETWEEN(1,16)>7,RANDBETWEEN(15,23),RANDBETWEEN(2,8)))

or

=IF(RANDBETWEEN(1,73)<=57,RANDBETWEEN(44,100),IF(RANDBETWEEN(1,16)<=9,RANDBETWEEN(15,23),RANDBETWEEN(2,8)))

will give you a random number with your criteria, but I am not too sure that this will hold statistically.

Each IF has a separate RANDBETWEEN as the test, so I am questioning whether the 2nd and 3rd arguments are "handicapped" by having to go through multiple selections.

It appears that the change from RANDBETWEEN(1,73) to RANDBETWEEN(1,16) handles this issue, but I cannot be sure that the results are in the correct proportions (7/73; 9/73; 57/73).

Regards,
Jay
Jay Petrulis is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 09:45 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes