+ Reply to Thread
Results 1 to 3 of 3

Random Number Generator based on specific constraints

Hybrid View

  1. #1
    Registered User
    Join Date
    01-24-2014
    Location
    Nebraska
    MS-Off Ver
    O365
    Posts
    5

    Random Number Generator based on specific constraints

    I am a working on a nutrition spread sheet for people that have to meet certain protein and carbohydrate requirements. On sheet one of the spreadsheet there is a list of different foods all with an ID number. On the second sheet is a meal plan showing what you are supposed to eat. The goal is to eat food that has a combine total of 15-20 grams of protien and 30 grams of carbohydrates per meal. What i want this spreadsheet to do is randomly select items from sheet one that adds together to meet the protein and carbohydrates required. Currently you just look on page one and find the id number of the food you want and type that number into the item# column on sheet two and it automatically fills in the information. The problem is that you end up eating the same foods all the time. Would like to figure out how to program this to randomly select foods that add up to the correct values.
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Random Number Generator based on specific constraints

    It will be not easy to do it with formulas, but at least you can prepere "a good startpoint for human adjustment".

    In your Listing sheet in J7 put random number generated by excel:
    =RAND()

    and copy down to next 7 cells
    in A11 in Monday sheet write a formula:
    =IF(AND(SUM(D$10:D10)<500,SUM(E$10:E10)<20,SUM(F$10:F10)<600),100+MATCH(SMALL('Food Listing'!$J$7:$J$14,ROW(1:1)),'Food Listing'!$J$7:$J$14,0),"")
    of course adjust allowed sums for D (calories) E (Fat) etc. add also next columns to be checked within AND(...) - carnb and prot.

    note that the sum is from row $10 to row 10 - so just one row with no numbers
    but as you copy this formula down it will become $10 to 11, $10 to 12 etc.

    once one of limits is met - next foods are not selected.

    Note, that results are volatile - if you change anything in a sheet (like deleting an empty cell ;-) the sheet will recalculate and you will receive another set of foods.

    Do silmilar with other types of food and you can start generating different sets.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-24-2014
    Location
    Nebraska
    MS-Off Ver
    O365
    Posts
    5

    Thumbs up Re: Random Number Generator based on specific constraints

    Kaper thanks for the help this really helped out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  2. Random Number Generator
    By gandhikr in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-22-2013, 11:43 AM
  3. Random number generator, discluding specific numbers
    By JVesuvius in forum Excel General
    Replies: 2
    Last Post: 01-02-2013, 12:43 PM
  4. Random number generation with constraints
    By sc11 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-14-2012, 12:41 AM
  5. Random Number Generator help
    By Shani in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2006, 11:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1