Skip to content

Latest commit

 

History

History
28 lines (24 loc) · 1.46 KB

File metadata and controls

28 lines (24 loc) · 1.46 KB

Plugins with generators

The used API is rather simple and requires an export of only one function: int gen_getinfo(GeneratorInfo *gi) that should fill the GeneratorInfo structure. The include/cinterface.h file contains some macros that allow to avoid some boilerplate code. Numerous examples of plugins are available in the generators directory. Requirements to PRNGs source code in plugins:

  • Must be freestanding, i.e. don't use any libraries including C standard library.
  • Must be reentrant, i.e. mustn't contain any mutable static or global variable. PRNG state should be kept in dynamically allocated structures.

Such requirements may seem unusual and too strict. But pseudorandom number generators should be small and fast programs that are trivially compilable into object code. Such approach greatly reduces dynamic libraries sizes, especially for Windows, and allows to load DLLs under DOS extenders. There are only two problematic situations:

  • Modulo operation on 64-bit numbers on 64-bit platforms and on 32-bit numbers on 32-bit platforms: some compilers use their runtime libraries for their implementation, at least in some cases. But such operations are usually expensive and require a manual optimization anyway.
  • Operations with 64-bit numbers on some ancient 32-bit compilers such as Open Watcom C/C++: it may use runtime for it. In SmokeRand there is a workaround for it by means of some linking hacks in the autogenerated Makefile.wat file.