Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created May 27, 2015 12:32
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 shigemk2/34fedb5f4cfa67b04dfa to your computer and use it in GitHub Desktop.
Save shigemk2/34fedb5f4cfa67b04dfa to your computer and use it in GitHub Desktop.
import System.Random
import Control.Monad(when)
main = do
gen <- getStdGen
askForNumber gen
askForNumber :: StdGen -> IO ()
askForNumber gen = do
let (randNumber, newGen) = randomR (1,10) gen :: (Int, StdGen)
putStrLn "Which number in the range from 1 to 10 am I thinking of? "
numberString <- getLine
when (not $ null numberString) $ do
let number = read numberString
if randNumber == number
then putStrLn "You are correct!"
else putStrLn $ "Sorry, it was " ++ show randNumber
-- 乱数ジェネレータを更新しながら無限に繰り返す
askForNumber newGen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment