Sample code for 30+ languages & platforms
DataFlex

Adding Entropy to a PRNG

See more PRNG Examples

Demonstrates how system entropy is automatically added when the application does not explicitly add entropy prior to generating the 1st random data. Also demonstrates how additional entropy can be added at anytime during the lifetime of the PRNG object.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Variant vFortuna
    Handle hoFortuna
    String sTemp1

    Move False To iSuccess

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Move False To iSuccess

    //  The simplest way to use the Chilkat PRNG is to instantiate the object
    //  and generate random data.  This skips the explicit step of getting system entropy
    //  and adding it (via get AddEntropy method).  When no entropy is explicitly added,
    //  Chilkat will automatically add 32-bytes of system entropy on the first request
    //  for random data.

    //  Generate some random data.
    //  The 1st call to GenRandom implicitly adds 32 bytes of system entropy to seed the PRNG.
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1

    //  Note: An application can get additional system entropy and add it at any point
    //  during the lifetime of the PRNG.  For example:
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGetEntropy Of hoFortuna 16 "hex" To sTemp1
    Get ComAddEntropy Of hoFortuna sTemp1 "hex" To iSuccess
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGetEntropy Of hoFortuna 16 "hex" To sTemp1
    Get ComAddEntropy Of hoFortuna sTemp1 "hex" To iSuccess
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGetEntropy Of hoFortuna 16 "hex" To sTemp1
    Get ComAddEntropy Of hoFortuna sTemp1 "hex" To iSuccess
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1
    Get ComGenRandom Of hoFortuna 16 "hex" To sTemp1
    Showln sTemp1


End_Procedure