RosettaCodeData/Task/Pick-random-element/Elena/pick-random-element.elena

15 lines
245 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
import extensions;
extension listOp
{
randomItem()
2026-02-01 16:33:20 -08:00
= self[Random.nextInt(self.Length)];
2023-07-01 11:58:00 -04:00
}
public program()
{
2026-02-01 16:33:20 -08:00
auto item := new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
2023-07-01 11:58:00 -04:00
2026-02-01 16:33:20 -08:00
Console.printLine("I picked element ",item.randomItem())
2023-07-01 11:58:00 -04:00
}