D Paste by Jesse Phillips
Description: Sellecting randomly from a range
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import std.algorithm; import std.random; import std.range; import std.stdio; string[] list = ["one", "two", "three", "four", "five"]; string[] list2 = ["1", "2", "3", "4", "5"]; void main(string[] args) { auto rnd = new Random(unpredictableSeed); int count = uniform(1, list.length, rnd); string[] result = new string[count*2]; fill(result[0..count], take(count, randomCover(list, rnd))); fill(result[count..$], take(count, randomCover(list2, rnd))); writeln(result); } |