+ Reply to Thread
Results 1 to 6 of 6

Number Shuffle

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Number Shuffle

    Hi, i have a problem that i have been trying to solve for some time.

    I have a fixed set of numbers in Row A that doesn't move, and i need to randomly shuffle the numbers in Row B.

    However the numbers in Row B must always be greater than the numbers in Row A.

    I have tried everything i can think of, including randomly shuffling them and using "Goal Seek" etc.. but to no avail.

    This feels like a Macro solution but i am rubbish at them!!

    Can anyone help?
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Number Shuffle

    I didn't use a macro. I think the hardest part of the solution was figuring out an algorithm that would be "random" while meeting the criteria that the result was always larger than the value in column A, not repeating, and so on. Here's what I did:

    1) I hope this is allowed, but, it occurred to me that it will be easier to choose a random number if I start with the "smallest" set of numbers (ie at the largest value of A) and work towards the smallest value of A. So I re-entered the values in A in "descending" order -- 20, 19, 18,...,2,1,20,19,...,1,20,...,1.
    2) I need to choose a random number between 21 and 33, but I want a way to "remove" the numbers that have been chosen so they cannot be chosen again (at least, until we start over), so I don't want a simple RANDBETWEEN(). I make a row of my available numbers in D1:P1. D1 is 21, E1 is 22, and so on to 33 in P1.
    3) Choose a random number from the list. RANDBETWEEN(1,13) will choose a random number between 1 and 13, and INDEX() will pull that entry from the list. B1 =INDEX(D1:P1,RANDBETWEEN(1,13))
    4) Now I need to make a new list that adds the next smaller integer to the list and removes the number chosen in step 3 from the list. I chose to simply replace the number chosen with the next available number.
    4a) MIN($D1:$P1)-1 will be next available number.
    4b) An IF() function can identify the number chosen and make the replacement. So, in D2, I enter =IF($B1=D1,MIN($D1:$P1)-1,D1). Copy/paste/fill into D2:P2. Note the mix of relative and absolute references for easy copying.
    5) Copy B1 down into B2 to choose another random number.
    6) Copy B2:P2 and paste down to B20. That should give me one complete set of random numbers where the number in column B is always greater than the number in column A. Note that I assume the values in column A decrease by 1 each time -- basically that your example is not oversimplified.
    7) Now make a copy of row 1 to row 20 and paste down for as many sets as I need to create.

    As noted, I have taken your example fairly literally, so, if it is oversimplified, additional work would be needed to modify this algorithm or come up with a new algorithm.

    Is that close to what you want? What difficulties do you run into in implementing that?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Re: Number Shuffle

    Hi, thanks for taking the time to help me with this & providing such a detailed reply.
    i tried to follow your instructions but struggled with some of the items.
    Could you attached this in excel please?

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,814

    Re: Number Shuffle

    Which step gave you trouble?

    Here's a file that I put together in LO Calc (it gave me a formatting compatibility warning, but I'm not sure what will fail to save correctly)
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    02-02-2012
    Location
    london
    MS-Off Ver
    Excel 2019
    Posts
    33

    Smile Re: Number Shuffle

    Thank you for this, its really appreciated.
    while the original brief was to keep all the numbers in column B & re-populate them to be greater than column A
    i.e. keep all numbers from 4 to 33 so that there will always 2 of every number no matter how that are shuffled

    I am more than happy with your solution & a simple "Goal Seek" run soon re-calculates your random numbers so that they meet my criteria.

    Your help is much appreciated & i am really grateful that you invested some of your time in helping me with this solution.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,460

    Re: Number Shuffle

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Euromillions Number Shuffle Help
    By snowman71 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-27-2020, 11:44 AM
  2. [SOLVED] Shuffle array VBA
    By sigit21 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-18-2018, 05:47 AM
  3. [SOLVED] Shuffle Right
    By keen2xl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2013, 01:40 AM
  4. Mix/shuffle cells around
    By kiapiggy in forum Excel General
    Replies: 4
    Last Post: 11-07-2011, 09:31 AM
  5. Excel 2007 : How to shuffle words in a row?
    By emil9216 in forum Excel General
    Replies: 9
    Last Post: 10-24-2011, 02:16 PM
  6. Shuffle Array
    By Rik Smith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2005, 12:05 PM
  7. Shuffle the cells!
    By M H in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2005, 04:05 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