Pick random element: Difference between revisions
Content added Content deleted
m (→{{header|RPL}}: optimized) |
(Added Dart) |
||
Line 608: | Line 608: | ||
const items = ["foo", "bar", "baz"]; |
const items = ["foo", "bar", "baz"]; |
||
items[uniform(0, $)].writeln; |
items[uniform(0, $)].writeln; |
||
}</syntaxhighlight> |
|||
=={{header|Dart}}== |
|||
{{trans|C}} |
|||
<syntaxhighlight lang="dart">import 'dart:math'; |
|||
void main() { |
|||
final array = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; |
|||
int i; |
|||
for (i = 1; i < 30; i++) { |
|||
var intValue = Random().nextInt(i) % 10; |
|||
print(array[intValue]); |
|||
} |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||