Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I use =INDEX($A1:$J1,ROUND(RAND()*COUNTA($A1:$J1),0)) in cell L1 to
N1 *to get 3 random numbers from my set of numbers. Sometimes I end up with ## instead of a random number in one of the cells? Anyone know why? Thanks There is a chance that ROUND(RAND()*COUNTA()) will be<0.5 And so rounds to 0 which is an invalid index -- Regards, Martin Brown Hmm, so is there a way to write this so that wouldn't happen? Someone else has alreay posted a suitable tweak. Also, is it possible to modify the formula so there would be no repeats? If you mean by no repeats so that it behaves like drawing numbered balls from a bag without replacement the short answer is NO, or at least doing it would be so clumsy that it isn't worthwhile. Simplest way to do that is have an InitMy_Random VBA function that copies the list of possible values to a private array, shuffles them a decent number of times by swapping a random pair of values and then returns the shuffled array each time the My_Random() is called until values run out when it should return #VALUE or some other "failed" flag. -- Regards, Martin Brown- Hide quoted text - - Show quoted text - Thanks for all your help :-) I won't worry about the repeats right now, the formulas you've given me will do what I need. Thanks again |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
RAND FUNCTION | Excel Worksheet Functions | |||
HELP with the RAND() Function!!!!!! | Excel Worksheet Functions | |||
Rand function | Excel Programming | |||
RAND FUNCTION | New Users to Excel | |||
Rand() function | Excel Discussion (Misc queries) |