Pick random element: Difference between revisions
Content deleted Content added
→{{header|Groovy}}: new solution |
|||
Line 192: | Line 192: | ||
fmt.Println(list[rand.Intn(len(list))]) |
fmt.Println(list[rand.Intn(len(list))]) |
||
}</lang> |
}</lang> |
||
=={{header|Groovy}}== |
|||
Solution: |
|||
<lang groovy>def list = [25, 30, 1, 450, 3, 78] |
|||
def random = new Random(); |
|||
(0..3).each { |
|||
def i = random.nextInt(list.size()) |
|||
println "list[${i}] == ${list[i]}" |
|||
}</lang> |
|||
Output: |
|||
<pre>list[3] == 450 |
|||
list[2] == 1 |
|||
list[5] == 78 |
|||
list[3] == 450</pre> |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |