You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was looking for code to do shuffle. I feel there are two problems with your solution:
the function mutates the list given to it (and sort of pretends that it didn't by returning the result of the shuffle additionally as it's return value)
it doesn't use existing code for shuffling
I wrote this code for my project:
/**
* Returns a randomized list.
*/
fun <T> Iterable<T>.shuffle(seed: Long? = null): List<T> {
val list = this.toMutableList()
val random = if (seed != null) Random(seed) else Random()
Collections.shuffle(list, random)
return list
}
It reuses existing code to do the shuffling and can be called like other kotlin collection functions.
The text was updated successfully, but these errors were encountered:
I was looking for code to do shuffle. I feel there are two problems with your solution:
I wrote this code for my project:
It reuses existing code to do the shuffling and can be called like other kotlin collection functions.
The text was updated successfully, but these errors were encountered: