View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Martin Brown Martin Brown is offline
external usenet poster
 
Posts: 230
Default Unique Random Numbers

On 08/09/2011 01:26, Paul Black wrote:
Hi,

I would like to generate unique random numbers from say 34 numbers,
and starting in "B2" list them in 5 number combinations going down
until ALL the 34 numbers have been used. I know in this example the
first 6 combinations will have 5 numbers and the 7th combination will
have only 4.
There may be occassions where there might be more or less numbers than
34 numbers and maybe 4,5,6 or 7 number combinations so code where I
could adapt it accordingly will be much appreciated.


The simplest way is to define them as 1...N sequentially and then
shuffle them with code to swap a pair chosen at random from the cells
range 1..N run this O(N^2) times and you get what you want.

Regards,
Martin Brown