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.
     
    Pranjal Jain, Apr 10, 2008
    #1
    1. Advertisements

  2. Pranjal Jain

    Heesob Park Guest

    Hi,

    If a list is given:

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

    You can do it like this:

    list.sort_by{rand}.first

    Regards,
    Park Heesob
     
    Heesob Park, Apr 10, 2008
    #2
    1. Advertisements

  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/
     
    Julian Leviston, Apr 10, 2008
    #3
  4. Pranjal Jain

    saras Guest

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.