Skip to content

Instantly share code, notes, and snippets.

@zats
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zats/b8d9da7effd89b0e5400 to your computer and use it in GitHub Desktop.
Save zats/b8d9da7effd89b0e5400 to your computer and use it in GitHub Desktop.
GKRandomDistribution vs GKShuffledDistribution
import Cocoa
import GameplayKit
let randoms = NSCountedSet()
let shuffles = NSCountedSet()
let gausians = NSCountedSet()
let randomD3 = GKRandomDistribution(lowestValue: 1, highestValue: 3)
let shuffledD3 = GKShuffledDistribution(lowestValue: 1, highestValue: 3)
let gausianD3 = GKGaussianDistribution(lowestValue: 1, highestValue: 3)
for i in 0..<30 {
randoms.addObject(randomD3.nextInt())
shuffles.addObject(shuffledD3.nextInt())
gausians.addObject(gausianD3.nextInt())
}
print("Random:")
randoms.forEach{
print("\($0) \(randoms.countForObject($0))")
}
print("Shuffled:")
shuffles.forEach{
print("\($0) \(shuffles.countForObject($0))")
}
print("Gausian:")
gausians.forEach{
print("\($0) \(gausians.countForObject($0))")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment