Thread: Random numbers
View Single Post
  #5   Report Post  
Harlan Grove
 
Posts: n/a
Default

wrote...
Bryan Hessey wrote:

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


... Or simply =RAND().


Stronger statement in order. There's a small chance of duplication of
integers using INT(RAND()*99999999). There's *NO* chance of duplication
using RAND() alone when only 15 numbers are involved. NEVER round
pseudorandom numbers unless you need the rounded results. If they're
only used in intermediate calculations, *ALWAYS* leave them as-is
(unrounded).

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. . . .


If the OP uses your simple =RAND() in row 1, this isn't an issue. The
only way you get duplicates from pseudorandom number generators is by
drawing more deviates than the period of the generator. The period of
Excel's generator is more than 1,000,000, so no duplicates in a range
of only 15 cells.

. . . I believe HLOOKUP() will
return the same value from $A2:O2. The probability of that
is increased with Bryan's INT(RAND()*N) approach.


It's possible in Bryan's approach *ONLY* when using his truncated
integer random deviates.

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.

....

If you have a single column, N row range D of distinct values, and you
want to draw a sample of size K <= N from D without replacement, then
all you need is another single column, N row range, RV, of distinct
random values (=RAND() sufficient for this) and formulas like

K1:
=INDEX(D,COUNTIF(RV,"<="&INDEX(RV,ROWS(K$1:K1))))

K1 filled down as far as needed.