The goal here is to select 4 unique index id's from a given list in Dart.
Hardcoded: source list, how many numbers to pick, zero excluded, printing the selected items list as having 4 elements.
import 'dart:math';
void main() {
List<int> numbers = [1, 2, 3, 4, 5,6,7,8,9];
List<int> pickedList =[];
/// pick 4 random numbers
for(var i=0; pickedList.length <4 ;i++) {
var picked = new Random().nextInt(numbers.length);
// skip the generated 0
if(picked >0 && !pickedList.asMap().containsValue(picked))
{
pickedList.add(picked);
} //for i to 4
} ///picked > 0 && not yet picked
print('Here are you selected numbers. No repeats');
print('=======');
for (var i =0; i<4; i++) {
print(pickedList[i]);
}
// print(pickedList.asMap());
} /// /main
void main() {
List<int> numbers = [1, 2, 3, 4, 5,6,7,8,9];
List<int> pickedList =[];
/// pick 4 random numbers
for(var i=0; pickedList.length <4 ;i++) {
var picked = new Random().nextInt(numbers.length);
// skip the generated 0
if(picked >0 && !pickedList.asMap().containsValue(picked))
{
pickedList.add(picked);
} //for i to 4
} ///picked > 0 && not yet picked
print('Here are you selected numbers. No repeats');
print('=======');
for (var i =0; i<4; i++) {
print(pickedList[i]);
}
// print(pickedList.asMap());
} /// /main