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 Mar 30th, 2002, 10:48 AM   #1
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

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

I'm pretty familiar with =RAND and also have the Analysis Toolpak installed

many thanks
Chris
Chris Davison is offline   Reply With Quote
Old Mar 30th, 2002, 10:58 AM   #2
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

this is not properly tested but,
in 1, say A1, cell put:

=RANDBETWEEN(1,30)

in the next cell put:

=IF(AND(A1>10,A1<=15),10-RANDBETWEEN(0,10),IF(AND(A1>15,A1<20),20+RANDBETWEEN(0,10),A1))

As I say not fully tested, let me know if it does the job for you.

_________________
Share the wealth!!
Ian Mac

[ This Message was edited by: Ian Mac on 2002-03-30 09:59 ]
Ian Mac is offline   Reply With Quote
Old Mar 30th, 2002, 11:02 AM   #3
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

oooops

sorry Ian, I know how irritating this can be :

I meant in a single formula

(Gawd, I can't believe I just did that)

thanks mate
Chris




ps - watchign the news ? Queen Mum dead

[ This Message was edited by: Chris Davison on 2002-03-30 10:02 ]
Chris Davison is offline   Reply With Quote
Old Mar 30th, 2002, 11:05 AM   #4
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

Why just one formula?

A UDF of a similar nature would do the job, but I'm assuming you don't want that?
__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old Mar 30th, 2002, 11:09 AM   #5
Ian Mac
MrExcel MVP
 
Join Date: Feb 2002
Location: Newcastle, UK
Posts: 1,174
Default

BLIMEY!! a little slow on your PS. cripes! I thought she'd go on and on.
__________________
"Have a good time......all the time"
Ian Mac
Ian Mac is offline   Reply With Quote
Old Mar 30th, 2002, 12:04 PM   #6
Jack in the UK
Board Regular
 
Join Date: Feb 2002
Posts: 3,065
Default

Chris

Come onyour my mate you know this will not be done unless some UDF sits behind so:

ChrisD_Lotter(range1... range6) works

No function does this in dafult MS selectable but what about if i slip in a COM file.. (thats and add in in the text i mean before i get shot) that would do it!

need the answer eh!

OK what you do cleaverly nest the formula so essentially one fornula wil that not do ?

IE IF(...
__________________
Free Excel based Web Toolbar available here.

Jack in the UK
J & R Excel Solutions
"making Excel work for you"
Jack in the UK is offline   Reply With Quote
Old Mar 30th, 2002, 08:39 PM   #7
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

Hi Chris


This works sometimes )

=TRIM(MID(RANDBETWEEN(1,10) & " " & RANDBETWEEN(20,30),RANDBETWEEN(1,3),RANDBETWEEN(1,2)))


Tends to return a blank at times though But may give you something to work on.
Dave Hawley is offline   Reply With Quote
Old Mar 30th, 2002, 11:16 PM   #8
eliW
Board Regular
 
eliW's Avatar
 
Join Date: Mar 2002
Posts: 1,805
Default

Hi Chris,
One formula:
=IF(RANDBETWEEN(0,1)=0,RANDBETWEEN(0,10),RANDBETWEEN(20,30))
This would work properly (true random) only if the two ranges are equal.
Regards,
Eli
eliW is offline   Reply With Quote
Old Mar 31st, 2002, 03:36 AM   #9
eliW
Board Regular
 
eliW's Avatar
 
Join Date: Mar 2002
Posts: 1,805
Default

Quote:
On 2002-03-30 22:16, eliW wrote:
Hi Chris,
One formula:
=IF(RANDBETWEEN(0,1)=0,RANDBETWEEN(0,10),RANDBETWEEN(20,30))
This would work properly (true random) only if the two ranges are equal.
Regards,
Eli
A little change which allow randomizing 2 different size of ranges, for example:
1-5,20-30
=IF(RANDBETWEEN(1,15)<=5,RANDBETWEEN(1,5),RANDBETWEEN(20,30))
Eli


[ This Message was edited by: eliW on 2002-03-31 02:38 ]
eliW is offline   Reply With Quote
Old Mar 31st, 2002, 03:49 AM   #10
Aladin Akyurek
MrExcel MVP
 
Aladin Akyurek's Avatar
 
Join Date: Feb 2002
Location: The Hague
Posts: 50,317
Default

Quote:
On 2002-03-31 02:36, eliW wrote:
Quote:
On 2002-03-30 22:16, eliW wrote:
Hi Chris,
One formula:
=IF(RANDBETWEEN(0,1)=0,RANDBETWEEN(0,10),RANDBETWEEN(20,30))
This would work properly (true random) only if the two ranges are equal.
Regards,
Eli
A little change which allow randomizing 2 different size of ranges, for example:
1-5,20-30
=IF(RANDBETWEEN(1,15)<=5,RANDBETWEEN(1,5),RANDBETWEEN(20,30))
Eli


[ This Message was edited by: eliW on 2002-03-31 02:38 ]
Eli,

Your first formula (slightly modified here) appears to me elegant and satisficing:

=IF(RANDBETWEEN(0,1),RANDBETWEEN(1,10),RANDBETWEEN(20,30))

The size of <1,10> is eq to that <20,30>. Is there something I'm missing?

Regards,

Aladin
Aladin Akyurek 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 12:49 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