eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RandomRDRand':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: RandomRDRand


Inheritance:

   Object
   |
   +--RandomRDRand

Package:
stx:libbasic2
Category:
Magnitude-Numbers-Random
Version:
rev: 1.13 date: 2021/01/20 15:59:35
user: cg
file: RandomRDRand.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


This generator uses the rdgen random generator which is built into modern intel chips.
Before using, you should check via the isSupported query.

Warning:
    there have been discussions about the security of the intel rdgen instruction
    and whether there are NSA backdoors built into it.
    Linus Torwalds refuses to use it for /dev/urandom in the linux kernel, for that very reason.
    Be sure you know what you are doing, if you use this generator for sensitive cryptographic stuff.
    We recommend using one of the libcrypt-based generators and use this only to get additional
    entropy for the seed.

Warning2:
    the initial release of the AMD Ryzen3000 (without BIOS update) has a bug in returning the same
    (all 1s) random number every time.
    The code here checks for that an raises an error in the constructor if that bug is detected.
    Be sure to catch this exception in your code and fall back to another random generator if raised.
    
NO WARRANTY

[usage:]
    RandomRDRand new nextInteger

copyright

COPYRIGHT (c) 2014 Claus Gittinger All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  new
self new nextInteger

o  new: seed
seed is actually ignored

queries
o  isSupported
true if this architecture supports hardware random numbers

Usage example(s):

     self isSupported


Instance protocol:

initialization
o  initialize
check for Ryzen RDRAND bug (returning the same all-ones everytime)

o  seed: seed
ignored

random numbers
o  nextBoolean
generates a boolean random

Usage example(s):

        |bag rng|

        rng := self new.
        bag := Bag new.
        100000 timesRepeat:[
            bag add:rng nextBoolean.
        ].
        bag

o  nextInteger
generates the next integer in 0..MAXINT.
Notice, it may raise an illegal instruction exception on some cpu chips,
even though the cpuid instruction says that it is available

Usage example(s):

     self new nextInteger



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:05:35 GMT