Pick random element: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) m →version 2: typo |
|||
Line 184: | Line 184: | ||
<lang coffeescript>array = [1,2,3] |
<lang coffeescript>array = [1,2,3] |
||
console.log array[Math.floor(Math.random() * array.length)]</lang> |
console.log array[Math.floor(Math.random() * array.length)]</lang> |
||
=={{header|CommonLisp}}== |
|||
<lang lisp>(defvar *list* '(one two three four five)) |
|||
(print (nth (random (length *list*)) *list*)) |
|||
(print (nth (random (length *list*)) *list*)) |
|||
(print (nth (random (length *list*)) *list*))</lang> |
|||
Output: |
|||
<pre>FIVE |
|||
THREE |
|||
ONE</pre> |
|||
=={{header|D}}== |
=={{header|D}}== |