+ Reply to Thread
Results 1 to 6 of 6

Help with Rand

  1. #1
    Jack
    Guest

    Help with Rand

    I am trying to randomly generate a series of numbers based on another series
    of numbers. If i have the numbers 1 to 15 sequentially in A1 to A15, then how
    do i randomly generate one of these numbers in C1. Currently i am trying -
    =RAND()*A1:A15, but this is not working. The numbers in A1:A15 may well
    change and this is why i don't want to simply use =RAND()*15

  2. #2

    RE: Help with Rand

    "Jack" wrote:
    > If i have the numbers 1 to 15 sequentially in
    > A1 to A15, then how do i randomly generate
    > one of these numbers in C1.


    =OFFSET(A1,RAND()*COUNT(A1:A15),0)

  3. #3
    Jack
    Guest

    RE: Help with Rand

    Thanks very much for the prompt reply.

    Could you maybe explain what you have done so that it will assist me in
    modifying this and future use of this? I am not sure as to why you need to
    reference A1 and what the Count does?

    "[email protected]" wrote:

    > "Jack" wrote:
    > > If i have the numbers 1 to 15 sequentially in
    > > A1 to A15, then how do i randomly generate
    > > one of these numbers in C1.

    >
    > =OFFSET(A1,RAND()*COUNT(A1:A15),0)


  4. #4
    Dirk Van de moortel
    Guest

    Re: Help with Rand

    "Jack" <[email protected]> wrote in message news:[email protected]...
    > Thanks very much for the prompt reply.
    >
    > Could you maybe explain what you have done so that it will assist me in
    > modifying this and future use of this? I am not sure as to why you need to
    > reference A1 and what the Count does?
    >
    > "[email protected]" wrote:
    >
    > > "Jack" wrote:
    > > > If i have the numbers 1 to 15 sequentially in
    > > > A1 to A15, then how do i randomly generate
    > > > one of these numbers in C1.

    > >
    > > =OFFSET(A1,RAND()*COUNT(A1:A15),0)


    Count() counts the number of non-empty cells in the
    specified range.
    If not all the cells in the range are filled, the function
    would fail because you would never get one of the
    values starting on and below the cell on the row
    corresponding to the number of non-empty cells.

    Since you have specified that all the cells between
    A1 and A15 are filled, the result will always be 15,
    so you don't need to do the counting and better use

    = OFFSET( A1, RAND()*15, 0 )

    which gives you the value of the cell which is
    rand()*15 rows below and 0 columns to the right
    of the reference cell A1.

    If you expect empty cells, and don't want to count
    and hardcode the number of rows in your range,
    then you can use the function ROWS(A1:A15):

    = OFFSET( A1, RAND()*ROWS( A1:A15 ), 0 )

    When it picks an empty cell, it will generate a zero.
    This works with a mix of empty and non-empty cells.

    Dirk Vdm



  5. #5

    RE: Help with Rand

    "Jack" wrote:
    > Could you maybe explain what you have done so that
    > it will assist me in modifying this and future use of this?
    > I am not sure as to why you need to reference A1 and
    > what the Count does?


    Use Help > Excel Help to learn about functions and their
    parameters. After your read the Help text, if you still
    have questions, fire away!

    I used COUNT() to generalize. You could replace COUNT()
    with 15.


  6. #6
    Harlan Grove
    Guest

    Re: Help with Rand

    [email protected] wrote...
    >"Jack" wrote:
    >>If i have the numbers 1 to 15 sequentially in
    >>A1 to A15, then how do i randomly generate
    >>one of these numbers in C1.

    >
    >=OFFSET(A1,RAND()*COUNT(A1:A15),0)


    COUNT is only useful when there might be some nonnumeric cells, but
    your formula would assume any nonnumeric cells were in the bottom rows
    of the range. If there might be nonnumeric cells in the range, better
    to use

    =LARGE(A1:A15,INT(1+COUNT(A1:A15)*RAND()))

    or

    =SMALL(A1:A15,INT(1+COUNT(A1:A15)*RAND()))

    If the range would always have all numeric cells, better either to
    hardcode the cell count or use ROWS rather than COUNT. Note that the
    LARGE and SMALL formulas above have no difficulty returning values from
    arbitrary ranges or even 3D references.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1