+ Reply to Thread
Results 1 to 7 of 7

Ommitting some values from randbetween function

  1. #1
    Registered User
    Join Date
    07-17-2009
    Location
    Bristol England
    MS-Off Ver
    Excel 2007
    Posts
    46

    Ommitting some values from randbetween function

    Hi, I need produce numbers from 2 to 10, but avoiding the factors of another random number. So my first randbetween(2,10) produces 3, then my next randbetween(2,10) produces 9, which isnt suitable. I need either 4,5,7,8,10. And a similar case with 2, I need to produce either 3,5,7,9. Is there a way to omit some numbers?

    Thanks
    Last edited by Geomarsh; 08-05-2009 at 07:36 AM.

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Ommitting some values from randbetween function

    unless someone comes up with a better way a1=randbetween(2,3) just to generate those 2 numbers b2 contains the result
    Attached Files Attached Files
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Ommitting some values from randbetween function

    There is probablya better solution to this but maybe this will work:

    A1: =RANDBETWEEN(1,10)
    B1: =RANDBETWEEN(1,10)
    C1: =IF(AND(ISEVEN(A1),ISODD(B1)),A1,0)
    D1: =IF(AND(ISEVEN(A1),ISODD(B1)),B1,0)

  4. #4
    Registered User
    Join Date
    07-17-2009
    Location
    Bristol England
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Ommitting some values from randbetween function

    Hi, I dont really understand how martindwilson's verision works, as i need to produce about 800 examples so cant see it working as a long column unless im being really blind?
    Second one works well, but if the if statements are false it just shows 0, which i cant use. what i want to do is produce a loop i think, so i want it to try a random number and then change it if it has a common factor or is a multiple of the first number iv produce. (I may have forgotten to add about the common factor into my orginal post!) As i am basically constructing a (proper) fraction that cant be simplified any farther.

    eg I am producing denominator first, so say it comes out as 10, i cant have 2,4,5,6,8
    If denom was 4, I cant have 2 as numerator.

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Ommitting some values from randbetween function

    ok try version 2
    Attached Files Attached Files

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Ommitting some values from randbetween function

    Choose a random row from this table:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  7. #7
    Registered User
    Join Date
    07-17-2009
    Location
    Bristol England
    MS-Off Ver
    Excel 2007
    Posts
    46

    Re: Ommitting some values from randbetween function

    Hi thansk veru much MartinDwilson, version 2 works brilliantly, saved me alot of time!
    Thanks

+ 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