+ Reply to Thread
Results 1 to 18 of 18

Random Number Set Generator & Recorder

  1. #1
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Random Number Set Generator & Recorder

    Hi

    Hope this makes sense?

    I’m using =INDEX($A$1:$J$1,RANK(A2,$A$2:$J$2)) to generate a random set of numbers in cells A4:E4

    Looking for a macro that can continually generate random sets of numbers until the set in cells A4:E4 match the number set in cells F8:J8 (number order not import), then record in cell L8 how many sets (ie 1325) of numbers were generated from the beginning until a match was made.

    Then continue generating random sets of numbers until a match (A4:E4) is made to the set of numbers in cells F9:J9 (number order not important), recording in cell L9 how many sets of numbers (ie 1644) it took for the match to happen AFTER the numbers in cells F8:J8 were matched. (ie 1325 sets of numbers were generated until the number set in cells F8:J8 was matched. Then it took another 1644 sets of numbers to be generated until the numbers in cells F9:J9 were matched)

    Then continue generating random sets until a match (A4:E4) is made to the set of numbers in cell F10:J10, recording in cell L10 how many sets of numbers (ie 1644) it took to match AFTER the numbers in cells F9:J9 were matched.

    If the recorded amount in cell L9 & L10 match (ie 1644) then generate that many more sets (1644) of numbers and record the numbers of the final set in cells F12:J12 and the value of cell L10 into cell L12.
    Then reset the recorded values in cell L8:L10 and start process over recording next match values into cells F13:J13 and L13 and so forth.

    Alternatively, once the number set in cells F10:J10 has been matched, if the recorded value in cell L9 & L10 don’t match, reset L8:L10 and have the process start over.
    Attached Files Attached Files

  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: Random Number Set Generator & Recorder

    If I understand the question, you don't need to simulate this to know the answer.

    Any combination is as likely as any other, and there are =combin(10,5) = 252 combinations, so every trial has a 1/252 chance of success.

    The result is a geometric distribution of the number of trials required until a match, which you can calculate using the negative binomial distribution:

    A
    B
    C
    D
    E
    1
    P(s)
    2
    0.00397
    B2: =1 / COMBIN(10, 5)
    3
    Trials
    PDF
    CDF
    4
    1
    0.00397
    0.00397
    B4: =NEGBINOM.DIST($A4 - 1, 1, $B$2, FALSE)
    5
    2
    0.00395
    0.00792
    C4: =NEGBINOM.DIST($A4 - 1, 1, $B$2, TRUE)
    6
    3
    0.00394
    0.01186
    7
    4
    0.00392
    0.01578
    8
    5
    0.00391
    0.01968
    9
    6
    0.00389
    0.02357
    10
    7
    0.00387
    0.02745
    11
    8
    0.00386
    0.03131
    12
    9
    0.00384
    0.03515
    13
    10
    0.00383
    0.03898
    14
    11
    0.00381
    0.04279
    15
    12
    0.00380
    0.04659
    16
    13
    0.00378
    0.05038
    17
    14
    0.00377
    0.05415
    18
    15
    0.00375
    0.05790
    19
    16
    0.00374
    0.06164
    20
    17
    0.00372
    0.06536
    21
    18
    0.00371
    0.06907
    22
    19
    0.00369
    0.07276
    23
    20
    0.00368
    0.07644
    24
    21
    0.00366
    0.08011
    25
    22
    0.00365
    0.08376
    26
    23
    0.00364
    0.08739
    27
    24
    0.00362
    0.09102
    28
    25
    0.00361
    0.09462


    You could generate random values from that distribution a lot faster than Monte Carlo trials.
    Last edited by shg; 03-12-2019 at 07:23 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    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: Random Number Set Generator & Recorder

    Random numbers from that distribution:

    A
    B
    3
    Random Value
    4
    168
    A4: =CEILING(LOG(1 - RAND(), 1 - 1/252), 1)
    5
    200
    6
    150
    7
    1
    8
    53
    9
    378
    10
    67
    11
    303
    12
    99
    13
    86
    14
    49
    15
    375
    16
    252
    17
    623
    18
    89
    19
    15
    20
    243
    Last edited by shg; 03-13-2019 at 09:02 AM.

  4. #4
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi shg

    Thanks for the info but my post wasn't really a question. The macro I'm looking for is part of larger project that I'm working on. I only used a search criteria of 5/10 to make it easier for testing. Once I have a working macro those numbers will be increased much larger which in turn will make getting results much longer, how much longer I don't know, but that's part of what I'm working on. Thanks again

  5. #5
    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: Random Number Set Generator & Recorder

    I'm looking for is part of larger project that I'm working on. I only used a search criteria of 5/10 to make it easier for testing. Once I have a working macro those numbers will be increased much larger which in turn will make getting results much longer
    That's motivation to use the proposed approach; it doesn't matter how large the result is.

    A search criteria of 15/30 would take an average 155 million iterations. Here, it's the same formula with different arguments.

  6. #6
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi shg

    Thanks again, but what I'm looking for is a macro that can do what I've asked. I know what you are suggesting is more efficient but I have my reasons why I want it the other way.

  7. #7
    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: Random Number Set Generator & Recorder

    Since I don't see any value in doing that, I leave you to the kind ministrations of others.

  8. #8
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi shg

    np, tnx again for your alternative suggestion

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Random Number Set Generator & Recorder

    I can provide a macro to do this but I don't understand when the process ends. Your description makes it sound like it goes on forever.

    Looking for a macro that can continually generate random sets of numbers until the set in cells A4:E4 match the number set in cells F8:J8....

    Then continue generating random sets of numbers until a match (A4:E4) is made to the set of numbers in cells F9:J9....

    Then continue generating random sets until a match (A4:E4) is made to the set of numbers in cell F10:J10....

    If the recorded amount in cell L9 & L10 match (ie 1644) then generate that many more sets (1644) of numbers and record the numbers of the final set in cells F12:J12 and the value of cell L10 into cell L12.

    Then reset the recorded values in cell L8:L10 and start process over....

    Alternatively, once the number set in cells F10:J10 has been matched, if the recorded value in cell L9 & L10 don’t match, reset L8:L10 and have the process start over....
    How do you know you're finished?

    And let's revisit this:

    If the recorded amount in cell L9 & L10 match (ie 1644) then generate that many more sets (1644) of numbers and record the numbers of the final set in cells F12:J12 and the value of cell L10 into cell L12.
    Generating 1644 (or any other number) sets of numbers and recording the last set is exactly equivalent, mathematically, to generating one set of numbers and recording that. What are you trying to get done there?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  10. #10
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi 6StringJazzer

    Yes, the process could go on forever, the process doesn't end until I stop the macro from running so I could end up with 1 - 10 - 100 results depending on how long I let it run for. If I use a large set of numbers such as 15/30 like shg suggested, I may have to let the macro run for several days if not weeks until I get the results I'm looking for. With a smaller set of number like 5/10 I could get results within a few days so I wouldn't need to let it run for so long.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Random Number Set Generator & Recorder

    The way you describe it, it keeps overwriting the results from each trial. Exactly as described, you will never see any results, until you stop the process, then you will only see the last trial. How do you want to capture those results? It sounds like you also need some kind of STOP button.

  12. #12
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi 6StringJazzer

    Yes, the values in L8:L10 are overwritten if there is a match or no match between L9:L10.

    Results will be captured in cells F12:L12, F13:L13, F14:L14 and on and on. These results don't get reset or over written.

    If there is a match between L9:L10 then that value is used to generate that many more random sets and the final set is recorded in cells F12:J12 and the match value is recorded in cell L12

    When another match happens, then the match value between L9:L10 is used to generate that many more random sets and the final set is recorded in cells F13:J13 and the match value is recorded in cell L13 and so on.

    A stop button would work or a counter that once X number of matches happen the macro stops? Can this be done??

  13. #13
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Random Number Set Generator & Recorder

    Here is a prototype but I don't think it does exactly what you want; it doesn't continually repeat the cycles. I would suggest using this as a starting point and coming back with specific questions if you get stuck.
    Attached Files Attached Files

  14. #14
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Random Number Set Generator & Recorder

    Instead of
    =INDEX($A$1:$J$1,RANK(A2,$A$2:$J$2))
    in A4:E4
    I'd use the arrayformula:
    =RANK(A2:J2;A2:J2)



  15. #15
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi 6StringJazzer

    I ran it manually a ton of times and when L9 & L10 did match, I got a "Run-time error 438, object doesn't support this property or method" ?

  16. #16
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Random Number Set Generator & Recorder

    On what line of code?

  17. #17
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Random Number Set Generator & Recorder

    Quote Originally Posted by ssjagger View Post
    Hi 6StringJazzer

    I ran it manually a ton of times and when L9 & L10 did match, I got a "Run-time error 438, object doesn't support this property or method" ?
    I discovered the problem. Remove the "s" from Values the two times it appears.

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    Excel 2007
    Posts
    107

    Re: Random Number Set Generator & Recorder

    Hi 6StringJazzer

    I did the edit as you suggested and it now works.

    I ran it manually again until I had a match in L9 & L10 and got results recorded in F12:J12 & L12, but when I started running it again the results were erased? Is it possible for those results to stay and then the results from the next match to be recorded in F13:J13 & L13 and so on?

+ 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. Random Number Generator
    By cliff2017 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-12-2017, 03:58 PM
  2. Random Number Generator
    By Chetan_raghu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2016, 08:56 AM
  3. Replies: 5
    Last Post: 06-21-2013, 10:40 AM
  4. Random Number Generator
    By gandhikr in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-22-2013, 11:43 AM
  5. Random number generator
    By sweetjonnycrash in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-12-2010, 02:54 PM
  6. [SOLVED] Need Random Number Generator
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-23-2006, 09:55 PM
  7. [SOLVED] Random Number generator
    By Neil M in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-01-2006, 02:10 PM

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