improved perlin basic blockgen

This commit is contained in:
2024-08-23 16:55:59 +10:00
parent efd9905f5b
commit 9ef60faa86
6 changed files with 105 additions and 11 deletions

View File

@ -0,0 +1,19 @@
public extension MutableCollection {
mutating func shuffle<T: RandomProvider>(using provider: inout T) {
guard self.count > 1 else {
return
}
for (first, remaining) in zip(self.indices, stride(from: 0x100, to: 1, by: -1)) {
let i = self.index(first, offsetBy: provider.next(in: remaining))
self.swapAt(first, i)
}
}
}
public extension Sequence {
func shuffled<T: RandomProvider>(using provider: inout T) -> [Self.Element] {
var copy = Array(self)
copy.shuffle(using: &provider)
return copy
}
}