Last active
August 29, 2015 14:27
-
-
Save zats/b8d9da7effd89b0e5400 to your computer and use it in GitHub Desktop.
GKRandomDistribution vs GKShuffledDistribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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