+ Reply to Thread
Results 1 to 11 of 11

Random number in specific range & Total

  1. #1
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Exclamation Random number in specific range & Total

    Friends,
    I like to randomly distribute #30 between 15 columns

    #30 Should be randomly distributed between the 15 columns
    Randome numbers should be generated between 0 to 5
    Total must be 30

    I use the following command to generate random numbers.
    =RANDBETWEEN(0,5)

    But how to fix the total to 30.

    Please check the attached file.

    Thanks
    Attached Files Attached Files
    Last edited by lavan_joy; 04-25-2012 at 06:47 AM.

  2. #2
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Random number in specific range & Total

    There is no problem about duplicate Randoms
    (Waiting for your solution friends)
    Last edited by lavan_joy; 04-24-2012 at 09:26 AM. Reason: updated

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Random number in specific range & Total

    Select B3:P3, pase =RandLen(30,,,TRUE) in the formula bar, press and hold the Ctrl and Shift keys, then press Enter.

    There is no limit on size, so there may be values > 5.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Random number in specific range & Total

    Hi shg,
    What are the other (non-relevant in this case) arguments in your UDF? The second one looks like a minimum value?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Random number in specific range & Total

    Thanks Mr.shg
    I'm not a expert in excel and couldn't understand your answer.Can anyone tell me about this briefly?
    OR
    You can update the formula in the above sample file and attach here
    Last edited by lavan_joy; 04-24-2012 at 10:27 AM. Reason: updated

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Random number in specific range & Total

    The code is for a UDF (User defined function)
    Copy and paste the code into a VBA module
    Alt + F11 opens the VBA Editor
    Insert> Module
    Paste code
    Close VBA Editor window (no need to save)

    Then Copy
    =RandLen(30,,,TRUE)
    Select your range which you want to add to 20 (i.e B3:P3)
    In the formula bar paste the formula and hit CNTRL SHFT ENTER
    That enters the formula as an array into the selected cells. You should see brackets around the formula {}
    Did that help?

  7. #7
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Random number in specific range & Total

    Quote Originally Posted by ChemistB View Post
    The code is for a UDF (User defined function)
    Copy and paste the code into a VBA module
    Alt + F11 opens the VBA Editor
    Insert> Module
    Paste code
    Close VBA Editor window (no need to save)

    Then Copy
    =RandLen(30,,,TRUE)
    Select your range which you want to add to 20 (i.e B3:P3)
    In the formula bar paste the formula and hit CNTRL SHFT ENTER
    That enters the formula as an array into the selected cells. You should see brackets around the formula {}
    Did that help?
    Thanks for the help. It works now.Is there any possibility to get the values between 0 to 5. The code gives >5 sometimes.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Random number in specific range & Total

    The function was designed to return a set of numbers with a Beta distribution. It would take some surgery to limit the maximum value, and it would change the distribution of the result. Someone else may have a suggestion that works better for you.

    @Chemist: Thank you.

  9. #9
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Random number in specific range & Total

    Quote Originally Posted by shg View Post
    The function was designed to return a set of numbers with a Beta distribution. It would take some surgery to limit the maximum value, and it would change the distribution of the result. Someone else may have a suggestion that works better for you.

    @Chemist: Thank you.
    Thanks a lot for the code SHG!
    Thanks for the instruction Chemist!!
    If you get any ideas please post it here chemist!

  10. #10
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Random number in specific range & Total

    Found an old shg code Treat similarly to above
    =RandTot(30,0,5) entered as an array
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    08-13-2009
    Location
    London,England
    MS-Off Ver
    Excel 2016
    Posts
    30

    Re: Random number in specific range & Total

    Thanks a lot Chemist for the help and thanks to SHG for coding.
    Reputation added to both of you Experts.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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