+ Reply to Thread
Results 1 to 8 of 8

Randon Number Selection formula that excludes previously selected number

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Randon Number Selection formula that excludes previously selected number

    I have to randomly select the order 3 values will go in. They are values 27, 28 and 29.

    So in cell C11 I have =randbetween(27,29). Easy enough.

    In cell E11, I want to randomly select a second number from the remaining pool of unused values.

    So let's say "28" comes up in C11. I need the formula in E11 to randomly select either 27 or 29. Then my third cell will obviously be the final value not selected by the first two formulas. I can do that by hand, unless there's a formula for that as well. That would be handy if there was because I have to repeat this for 60 rows.

    I was messing around with "=SMALL" but can't quite get it right.

    =SMALL(IF(C11={27,28,29},"",{27,28,29}),RANDBETWEEN(27,29))


    Any help would be appreciated!

    Thanks.

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

    Re: Randon Number Selection formula that excludes previously selected number

    one way
    for 3 separate from 27 to 29
    a1=RANDBETWEEN(27,29)
    b1 =IF(A1=27,CHOOSE(RANDBETWEEN(1,2),28,29),IF(A1=28,CHOOSE(RANDBETWEEN(1,2),27,29),IF(A1=29,CHOOSE(RANDBETWEEN(1,2),27,28))))
    c1=84-SUM(A1:B1)
    "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

  3. #3
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Randon Number Selection formula that excludes previously selected number

    First Random
    =INDEX({27;28;29},RANDBETWEEN(1,3))

    Second Random
    =SMALL(INDEX(({27;28;29}<>C11)*({27;28;29}),0,0),RANDBETWEEN(2,3))

    Last
    =SUMPRODUCT(({27;28;29}<>C11)*({27;28;29}<>E11)*({27;28;29}))
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

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

    Re: Randon Number Selection formula that excludes previously selected number

    in that case ,i like the second one but
    c11=RANDBETWEEN(27,29)
    d11 =SMALL(INDEX(({27;28;29}<>C11)*({27;28;29}),0,0),RANDBETWEEN(2,3))
    =84-SUM(C11:D11)
    would be shorter

  5. #5
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Randon Number Selection formula that excludes previously selected number

    Awesome! That's my very first successful use of INDEX to 'float' an array.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Randon Number Selection formula that excludes previously selected number

    Or this.....

    A1 =CHOOSE(RANDBETWEEN(1,3),27,28,29)
    B1 =CHOOSE(MATCH(TRUE,INDEX({27,28,29}<>A1,0),0),27,28,29)
    C1 =84-SUM(A1:B1)
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

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

    Re: Randon Number Selection formula that excludes previously selected number

    @sktneer
    that doesnt give a random second number
    =CHOOSE(MATCH(TRUE,INDEX({27,28,29}<>A2,0),0),27,28,29) will always give 27 if a1 is 28 or 29

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Randon Number Selection formula that excludes previously selected number

    My initial attempt was to find the first not-match, and randomly choose between that and a BigNum Lookup which pulls the last not-match.

    84-SUM is so brilliant. I feel so humbled by its simplicity.

+ 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. help with ranking using closest number to number selected to break a tie
    By Drastic in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-25-2013, 02:43 PM
  2. Randon Selection of Cells in Column
    By Trax in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-23-2012, 05:06 AM
  3. Replies: 4
    Last Post: 04-19-2010, 11:12 PM
  4. randon number
    By CobraLAD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2008, 07:01 AM
  5. Excel formula for number selection
    By Ernest35 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-11-2007, 06:08 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