Skip to content

Instantly share code, notes, and snippets.

@ysnrkdm
Created October 30, 2016 08:25
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 ysnrkdm/0b6a86603a0dbb83166287ed50e46297 to your computer and use it in GitHub Desktop.
Save ysnrkdm/0b6a86603a0dbb83166287ed50e46297 to your computer and use it in GitHub Desktop.
import Foundation
import RandomGenerator
let seed = Date().hashValue
RandomGeneratorXor128.seed = seed
print("Seed set: \(seed)")
var randHelper = RandomGeneratorXor128.generator()
_ = randHelper.getNextRandomUInt()
_ = randHelper.getNextRandomUInt()
_ = randHelper.getNextRandomUInt()
_ = randHelper.getNextRandomUInt()
var rand = randHelper.getNextRandomUInt()
rand = rand%100
while(true) {
print("Your guess? [0-99, >=100 to exit]")
let n: UInt = UInt(readLine()!)!
if (n >= 100) {
break
} else if (n == rand) {
print("Bingo!\nGenerating next number...")
var rand = randHelper.getNextRandomUInt()
rand = rand%100
} else if (n < rand) {
print("More!")
} else /* n > rand */ {
print("Less!")
}
}
print("Bye!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment