+ Reply to Thread
Results 1 to 14 of 14

Number Generator

  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    Niagara Falls
    MS-Off Ver
    Excel 2007
    Posts
    5

    Number Generator

    I have numbers from 1 to 75 and need to make all possible four number combinations from these numbers. Such as: 30,75,15,44 or 52,66,71,3 etc. as long as there are no repeating sets of four numbers. Is this at all possible? First time user here so I hope I am posting this properly.

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

    Re: Number Generator

    There are 1,215,450 such combinations. What would you do after you listed them?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-07-2010
    Location
    Niagara Falls
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Number Generator

    I will not use all the combinations. I may need 1000 combinations for this project and next week I may need 500 different combinations. I just need to know that there are not any repeats per even or generation of combinations. I also hope that this will show me how to do future random combinations with say three number combinations from 15 different numbers. Or two number combinations from 20 different numbers. And so on. Is there any answer to my inquiry?

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

    Re: Number Generator

    You could use a UDF:
    Please Login or Register  to view this content.
    To pick a random combination of 75 choose 5, select a 4-wide array of cells and array-enter this formula:

    =aiComboByNum(75, 4, RANDBETWEEN(0, COMBIN(75, 4) - 1))

    The first (zeroth) combination is

    =aiComboByNum(75, 4, 0) = 3 2 1 0

    and the last is

    =aiComboByNum(75, 4, 1215449) = 74 73 72 71

  5. #5
    Registered User
    Join Date
    01-07-2010
    Location
    Niagara Falls
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Number Generator

    Thank you ... I'm not sure what to do with it but I certainly will try. I have used excel for years and only really used it's formulas. I assume this is used through the developer ?

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

    Re: Number Generator

    Yes.

    Adding a Macro to a Code Module – Excel 2007
    1. Copy the code from the post
    2. Click the Developer tab, then Visual Basic
    3. From the menu bar in the VBE window, do Insert > Module
    4. Paste the code in the window that opens
    5. Press Alt+Q to close the VBE and return to Excel

  7. #7
    Registered User
    Join Date
    01-07-2010
    Location
    Niagara Falls
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Number Generator

    Thank you so much for your patience and knowledge. I completed the five steps (using the code in the window) and I am left looking at a blank worksheet. Now I’m not sure how to generate a list of numbers once I am looking or working in the worksheet. Right now it is blank. What do I have to do to obtain a list of random four number combinations? (73, 2, 33, 69).
    Thanks again for your help.

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

    Re: Number Generator

    Enter the first formula I gave exactly as described.

  9. #9
    Registered User
    Join Date
    01-07-2010
    Location
    Niagara Falls
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Number Generator

    I went to the blank work sheet and entered: =aiComboByNum(75, 4, RANDBETWEEN(0, COMBIN(75, 4) - 1))
    and the result is : #NAME?

  10. #10
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Number Generator

    there is a typo in the code the first line should read
    Please Login or Register  to view this content.
    dont forget to array enter it with ctrl+shift+ enter
    see here
    http://office.microsoft.com/en-us/ex...872901033.aspx
    Last edited by martindwilson; 01-10-2010 at 10:57 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

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

    Re: Number Generator

    Quote Originally Posted by Chris
    I went to the blank work sheet and entered: =aiComboByNum(75, 4, RANDBETWEEN(0, COMBIN(75, 4) - 1))
    and the result is : #NAME?
    Sounds like you didn't get the code installed. See attached. Before you open the workbook, set macro security to Disable all macros with notification, and then enable macros when prompted.

    Quote Originally Posted by Martin
    there is a typo in the code the first line should read
    There's no typo, Martin, it's correct as written.

    Quote Originally Posted by Martin
    dont forget to array enter it with ctrl+shift+ enter
    True, thanks for the emphasis.
    Attached Files Attached Files

  12. #12
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Number Generator

    hm it fails like that but works with the correction tho. i get name error using as you posted but it gives the results you posted when the last As Long() is omited then again i didnt test it in 2007 but in 97
    edit just tried in 2007 ok hmmmmmmmmmmmm
    Attached Images Attached Images
    Last edited by martindwilson; 01-10-2010 at 01:59 PM.

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

    Re: Number Generator

    I tested in 2003 and 2007; don't have anything older.

  14. #14
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Number Generator

    i see what you mean ,must be a version thing

+ 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