Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE ForeignFunctionInterface #-}
- import Foreign
- import Foreign.C.String
- import Foreign.C.Types
- import System.Win32.DLL
- import Control.Applicative
- import Data.Word
- type Error_t = Int
- type Func = Ptr Word32 -> IO Error_t
- foreign import ccall "dynamic" rand_s_func :: FunPtr Func -> Func
- rand_s = do
- lib <- loadLibrary "msvcrt.dll"
- rand_s_ptr <- rand_s_func . castPtrToFunPtr <$> getProcAddress lib "rand_s"
- alloca $ \ptr -> rand_s_ptr ptr >> peek ptr
- read4Bytes =
- let f x = map (flip mod (2^8) . div x . (2^) . (8*)) [0..3]
- in f <$> rand_s
Add Comment
Please, Sign In to add comment