Guest User

Untitled

a guest
Jun 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. {-# LANGUAGE ForeignFunctionInterface #-}
  2.  
  3. import Foreign
  4. import Foreign.C.String
  5. import Foreign.C.Types
  6. import System.Win32.DLL
  7.  
  8. import Control.Applicative
  9. import Data.Word
  10.  
  11. type Error_t = Int
  12. type Func = Ptr Word32 -> IO Error_t
  13.  
  14. foreign import ccall "dynamic" rand_s_func :: FunPtr Func -> Func
  15.  
  16. rand_s = do
  17. lib <- loadLibrary "msvcrt.dll"
  18. rand_s_ptr <- rand_s_func . castPtrToFunPtr <$> getProcAddress lib "rand_s"
  19. alloca $ \ptr -> rand_s_ptr ptr >> peek ptr
  20.  
  21. read4Bytes =
  22. let f x = map (flip mod (2^8) . div x . (2^) . (8*)) [0..3]
  23. in f <$> rand_s
Add Comment
Please, Sign In to add comment