+ Reply to Thread
Results 1 to 3 of 3

Generate random non-repeated range of numbers?

  1. #1
    Registered User
    Join Date
    06-17-2009
    Location
    Northeast, USA
    MS-Off Ver
    Excel Mac 2008
    Posts
    3

    Question Generate random non-repeated range of numbers?

    Hi,

    I need to generate a range of numbers in random order without them being repeated, from a specific starting value.

    So let's say the starting value was 500...I want to generate a very long cell (not column with each value) containing "500001 | 500007 | 500509 | 500622 | 500398 and so on...it would be from 500000 to 500999.

    The reason I need it to be like that is because I'm working with a csv and I need to store this randomized-order range as one large field in the CSV...each line of the CSV contains a different starting value. So I want the CSV to look like this

    "500","500001 | 500007 | 500509 | 500622 | 500398 etc."
    "400","400409 | 400831 | 400299 | 400005 | 400674 etc."

    Any tips/suggestions? I'm using Excel Mac 2008 but I do have access to the PC version at another location where I could do this if need be. Is Excel even the best tool to do this?

    Thanks!

    Edit: the pipe is just part of the text formatting I want...I wasn't using the pipe to designate a column beginning or anything. The application this is being fed into processes based on the | as the delimiter in that field of the CSV.
    Last edited by satoshi; 06-17-2009 at 02:11 AM. Reason: clarification

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Generate random non-repeated range of numbers?

    You will need to do this on another machine as your best bet would be to use a VBA dependent UDF (not available on Mac2008).

    You will find a lot of examples of how to generate (with VBA) a unique random list between two values, your tweak to that code will be to Join the resulting values in the resulting Array of unique randoms into one string with your pipe delimiter as opposed to returning each value to a separate range.

    For starters see: http://www.exceltip.com/st/Return_ra...Excel/531.html

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

    Re: Generate random non-repeated range of numbers?

    if you dont mind a bit of messing around
    1, format columns a and b as text
    2 in a1 and a2 put 500
    3. in b1 put 000 in b2 001
    4. in c1 &c2 put =rand()
    5 in d1 put =a1&b1 & in d2 put =a2&b2
    6.select a1:d2 and drag down to row 1000
    7.select data and sort by col C
    you now have 500000-500999 sorted randomly in col D
    8. open word
    9. copy col D and paste special(from the edit menu) as unformatted text
    10 in word select all
    11.open find/replace
    12. replace ^p with " | " (without quotes,assuming you need space either side of pipe) ^p is the paragraph mark from the special characters in word
    13. replace all
    14. you can now copy/paste all that into a cell (paste special ,text)in excel
    15. go back to your random gen sheet find replace 500 in col A with 400
    re-sort by col C and repeat process.
    it doesn't take long at all in fact it took me longer to write this than do it say 20 times.
    Last edited by martindwilson; 06-17-2009 at 05:58 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

+ 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