List<int> pickRandomInts(List<int> arr, int n, int seed) { int current = seed; Set<int>…
Jump to turn (16)
- 1List pickRandomInts(List arr, int n, int seed) { int current = seed; Set randomI
- 2please format it as Dart code block
- 3lets test it. original list is list of consecutive integers from 0 to 10 not inc
- 4now length 4
- 5compare the list of 3 and 4 integers
- 6modify that smaller destination list is a strict subset of bigger destination li
- 7now test it on original list of consecutive integers from 0 to 10 with seed 6942
- 8now length 4
- 9compare two lists
- 10dont use builtin dart random
- 11test it as the past time with 3 and 4
- 12now acknowledge we are using the same seed everywhere and compare outputs
- 13list of 3 is not a subset of list 4
- 14now seed given function with 69420. produce outputs for length 3 and 4. then com
- 15integer 4 is not present in the list of 4 somehow
- 16modify the function accordingly
- User
List pickRandomInts(List arr, int n, int seed) { int current = seed; Set randomIndexes = Set(); while (randomIndexes.length < n) { current = ((current * 0x41C64E6D) ^ current) >> 30; // use snippet to update current int index = current % arr.length; randomIndexes.add(index); } List randomInts = []; for (int index in randomIndexes) { randomInts.add(arr[index]); } randomInts.sort(); return randomInts; } change the function such that increasing n (length of output) will always contain smaller lengths as a subset
- Assistant