Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default RAND() function error? ##

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RAND FUNCTION NADTARVIN Excel Worksheet Functions 1 September 29th 06 05:56 AM
HELP with the RAND() Function!!!!!! denise1082 Excel Worksheet Functions 15 July 31st 06 07:54 AM
Rand function Alexander Fischer Excel Programming 8 May 23rd 06 05:02 PM
RAND FUNCTION theo499 New Users to Excel 2 April 11th 06 05:08 AM
Rand() function SMANDA Excel Discussion (Misc queries) 1 February 8th 05 12:59 AM


All times are GMT +1. The time now is 04:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"