+import ctypes
+
+
+class RandomnessIO:
+ """"Interface to libplomrogue's pseudo-randomness generator."""
+
+ def set_seed(self, seed):
+ libpr.seed_rrand(1, seed)
+
+ def get_seed(self):
+ return libpr.seed_rrand(0, 0)
+
+ def next(self):
+ return libpr.rrand()
+
+ seed = property(get_seed, set_seed)
+
+
+def prep_library():
+ """Prepare ctypes library at ./libplomrogue.so"""
+ libpath = ("./libplomrogue.so")
+ if not os.access(libpath, os.F_OK):
+ raise SystemExit("No library " + libpath + ", run ./compile.sh first?")
+ libpr = ctypes.cdll.LoadLibrary(libpath)
+ libpr.seed_rrand.argtypes = [ctypes.c_uint8, ctypes.c_uint32]
+ libpr.seed_rrand.restype = ctypes.c_uint32
+ libpr.rrand.argtypes = []
+ libpr.rrand.restype = ctypes.c_uint16
+ return libpr