Sermed mayi
Sermed mayi

Reputation: 757

Flutter : How creat new list with changed index from exist list?

if I have this List in Flutter :

var myList = ["a","b" , "c" , "d"];

How to create new list from myList by random index for each value like :

   ["b","c" , "a" , "d"];

or :

   ["a","c" , "d" , "b"];

or any other random list

Upvotes: 1

Views: 57

Answers (3)

Try this:

var myList = ["a", "b", "c", "d"];
myList.shuffle();

Upvotes: 0

Ibrahim Ali
Ibrahim Ali

Reputation: 2511

var newList = [...myList];
newList.shuffle();

Upvotes: 2

Robert Csete
Robert Csete

Reputation: 15

import random

myList = ["a","b" , "c" , "d"];
random.shuffle(myList)

print(mylist)

You follow this https://www.w3schools.com/python/ref_random_shuffle.asp

Upvotes: 1

Related Questions