to select random number from select list

Discussion in 'Ruby' started by Pranjal Jain, Apr 10, 2008.

  1. Pranjal Jain

    Pranjal Jain Guest

    HI
    I am having a list. I want to select a number in random from that list?
    which command I can use it for doing this?

    For example :

    $ie.row:)class =>"bgTableAltColors",:index
    =>"4").cell:)class,"padTableRightBorder").select_list:)class,"Formelement").option:)text,"Test
    Automation - Scripting").select

    here instead of "Test automation -scripting" I want to select a option
    in random.
    How can i do it ?

    Please help.
    Thanks in advance.
    --
    Posted via http://www.ruby-forum.com/.
    Pranjal Jain, Apr 10, 2008
    #1
    1. Advertising

  2. Pranjal Jain

    Heesob Park Guest

    Hi,

    Pranjal Jain wrote:
    > HI
    > I am having a list. I want to select a number in random from that list?
    > which command I can use it for doing this?
    >
    > For example :
    >
    > $ie.row:)class =>"bgTableAltColors",:index
    > =>"4").cell:)class,"padTableRightBorder").select_list:)class,"Formelement").option:)text,"Test
    > Automation - Scripting").select
    >
    > here instead of "Test automation -scripting" I want to select a option
    > in random.
    > How can i do it ?
    >
    > Please help.
    > Thanks in advance.

    If a list is given:

    list = ["a","b","c"]

    You can do it like this:

    list.sort_by{rand}.first

    Regards,
    Park Heesob
    --
    Posted via http://www.ruby-forum.com/.
    Heesob Park, Apr 10, 2008
    #2
    1. Advertising

  3. To get a random element from an array

    some_array[rand(some_array.size)]

    Julian.

    Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
    VIDEO #3 out NOW!
    http://sensei.zenunit.com/


    On 10/04/2008, at 6:59 PM, Pranjal Jain wrote:

    > HI
    > I am having a list. I want to select a number in random from that
    > list?
    > which command I can use it for doing this?
    >
    > For example :
    >
    > $ie.row:)class =>"bgTableAltColors",:index
    > =
    > >

    > "4
    > ").cell
    > :)class
    > ,"padTableRightBorder
    > ").select_list:)class,"Formelement").option:)text,"Test
    > Automation - Scripting").select
    >
    > here instead of "Test automation -scripting" I want to select a
    > option
    > in random.
    > How can i do it ?
    >
    > Please help.
    > Thanks in advance.
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    Julian Leviston, Apr 10, 2008
    #3
  4. Pranjal Jain

    saras Guest

    Re: to select random number from select list

    On Apr 10, 2:37 am, Julian Leviston <> wrote:
    > To get a random element from an array
    >
    > some_array[rand(some_array.size)]
    >
    > Julian.
    >
    > Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
    > VIDEO #3 out NOW!http://sensei.zenunit.com/
    >
    > On 10/04/2008, at 6:59 PM, Pranjal Jain wrote:
    >
    >
    >
    > > HI
    > > I am having a list. I want to  select a number in random from that  
    > > list?
    > > which  command I can use it for doing this?

    >
    > > For example :

    >
    > > $ie.row:)class =>"bgTableAltColors",:index
    > > =

    >
    > > "4
    > > ").cell
    > > :)class
    > > ,"padTableRightBorder
    > > ").select_list:)class,"Formelement").option:)text,"Test
    > > Automation - Scripting").select

    >
    > > here instead of "Test automation -scripting" I want to  select a  
    > > option
    > > in random.
    > > How can i do it ?

    >
    > > Please help.
    > > Thanks in advance.
    > > --
    > > Posted viahttp://www.ruby-forum.com/.- Hide quoted text -

    >
    > - Show quoted text -


    wow you love thouse videos
    saras, Apr 10, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. xeys_00
    Replies:
    12
    Views:
    843
    Jonathan Arnold
    Apr 11, 2005
  2. dungdang
    Replies:
    3
    Views:
    1,008
  3. globalrev
    Replies:
    4
    Views:
    742
    Gabriel Genellina
    Apr 20, 2008
  4. Alex Untitled
    Replies:
    11
    Views:
    648
    Giampiero Zanchi
    Nov 16, 2009
  5. VK
    Replies:
    15
    Views:
    1,116
    Dr J R Stockton
    May 2, 2010
Loading...

Share This Page