Thread: Random numbers
View Single Post
  #3   Report Post  
 
Posts: n/a
Default

Bryan Hessey wrote:
The problem is that you want random, and unique which
means not random.


That is incorrect. The OP simply wants random selection
"without replacement". Very common requirement. Nothing
less random about it.

You can achieve your results by putting in cells A1 to O1
=int(rand()*99999999)


.... Or simply =RAND().

in cells A2 to O2 the numbers 1 to 15
in cells A3 to O3
=HLOOKUP(SMALL($A1:$O1,COLUMN()),$A1:$O2,2,FALSE)


That is a nice idea, but I don't believe it is guaranteed
to give unique values. Consider the rare case when RAND()
gives the same result twice. I believe HLOOKUP() will
return the same value from $A2:O2. The probability of that
is increased with Bryan's INT(RAND()*N) approach.

Normally I manually sort $A1:$O2 (in Bryan's example) based
on column A. If there are duplicates in $A1:$O1, the order
of corresponding unique values in $A2:$O2 is "arbitrary".
(But not unpredictable. It depends on the sort algorithm).

I would like to avoid the manual sort myself. Building on
Bryan's idea, if we could determine the column that the
SMALL() value came from, we could build a reference to
$A2:$O2 using OFFSET() or similar functions.

Offhand, I do not know how to do that. Hopefully, someone
else can offer a solution.

I believe that other threads on the same subject point to
one or another MVP's web site with solutions. Search for
"random" in the Excel newsgroups/forums.

-----

john liem Wrote:
I want to generate numbers (1 to 15) in cells A1 through O1, but the
number in each cells should be unique compare to the other cells, how
can I do it? If I use =randbetween(1,15), I can not get unique number
in each cell, some numbers are duplicated.