Nat Strangerweather
06/03/2022, 5:24 PMprivate fun shakeLetterBag(slice: IntRange): Array<Letter> {
repository.arr.shuffle()
return repository.arr.sliceArray(slice)
}
var boardLetters = MutableLiveData(repository.arr)
fun loadTiles(): Array<Letter>? {
boardLetters.value = shakeLetterBag(0..27)
return boardLetters.value}
I am wondering if there is something wrong with my logic because I seem to be getting the occasional identical set, which statistically should not be the case. Any ideas? 🤔Ruckus
06/03/2022, 5:37 PM33..67
and that would somehow be meaningful, but the logic suggests otherwise.Nat Strangerweather
06/03/2022, 5:40 PMNat Strangerweather
06/03/2022, 5:41 PMephemient
06/03/2022, 5:42 PMephemient
06/03/2022, 5:42 PMNat Strangerweather
06/03/2022, 5:44 PMephemient
06/03/2022, 5:49 PMLandry Norris
06/03/2022, 5:55 PMNat Strangerweather
06/03/2022, 6:08 PMLandry Norris
06/03/2022, 6:14 PMLandry Norris
06/03/2022, 6:16 PMimport java.util.Random
/**
* You can edit, run, and share this code.
* <http://play.kotlinlang.org|play.kotlinlang.org>
*/
fun main() {
val random = Random(10273)
repeat(20) {
println(random.nextInt())
}
println("Resetting...")
val random2 = Random(10273)
repeat(20) {
println(random2.nextInt())
}
}
You’ll see that both runs print the same results.ephemient
06/03/2022, 6:21 PMshuffle()
uses is seeded once and not cloned. but you can verify by creating your own Random
(one, not every time) and explicitly passing it to shuffle
Nat Strangerweather
06/03/2022, 6:23 PMNat Strangerweather
06/03/2022, 6:23 PMNat Strangerweather
06/03/2022, 6:25 PMLouis Gautier
06/03/2022, 7:12 PMList(90) { it }
.shuffled()
.take(28)
?Nat Strangerweather
06/03/2022, 7:24 PMLouis Gautier
06/03/2022, 7:26 PM.distinct()
before .take()
Nat Strangerweather
06/03/2022, 7:31 PMNat Strangerweather
06/03/2022, 7:39 PMNat Strangerweather
06/03/2022, 7:39 PMLandry Norris
06/03/2022, 7:41 PMNat Strangerweather
06/03/2022, 7:41 PMprivate fun shakeLetterBag(count: Int): Array<Letter> {
val listArr = repository.arr.toList()
listArr
.shuffled()
.take(count)
return listArr.toTypedArray()
}
Landry Norris
06/03/2022, 7:42 PMNat Strangerweather
06/03/2022, 7:42 PMLouis Gautier
06/03/2022, 7:42 PMLandry Norris
06/03/2022, 7:42 PMreturn listArr
.shuffled()
.take(count).toTypedArray()
Landry Norris
06/03/2022, 7:43 PMNat Strangerweather
06/03/2022, 7:45 PMprivate fun shakeLetterBag(count: Int): Array<Letter> {
val listArr = repository.arr.toList()
return listArr
.shuffled()
.take(count).toTypedArray()
}
Louis Gautier
06/03/2022, 7:46 PMprivate fun shakeLetterBag(count: Int): Array<Letter> {
return repository.arr.toList()
.shuffled()
.take(count).toTypedArray()
}
Nat Strangerweather
06/03/2022, 7:46 PMNat Strangerweather
06/03/2022, 7:46 PMLouis Gautier
06/03/2022, 7:47 PM