• Random Class

    From Jack@3:633/280.2 to All on Fri Jul 11 03:19:03 2025
    Simulating a coin flip using C++'s <random> header file.


    /*
    * Compile in Visual studio:
    * cl /EHsc /std:c++20 main.cpp
    */
    #include <iostream>
    #include <random>

    using namespace std;

    int main()
    {
    std::random_device random_device;
    std::mt19937 random_engine{random_device()};
    std::uniform_int_distribution<int> distribution{0, 1};

    int heads = 0; int tails = 0;

    for (int p = 0; p < 10000; p++)
    {
    int coinFlip = distribution(random_engine);

    if (coinFlip == 0)
    heads++;
    else
    tails++;
    }

    cout << "Heads: " << heads << " Tails: " << tails << endl;
    cout << "Heads: " << (double)heads*100/10000 << "% Tails: " << (double)tails*100/10000 << "%" << endl;
    }
    /*
    * Typical output:
    * Heads: 5066 Tails: 4934
    * Heads: 50.66% Tails: 49.34%
    */


    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: To protect and to server (3:633/280.2@fidonet)
  • From Mr Flibble@3:633/280.2 to All on Fri Jul 11 04:00:30 2025
    On Thu, 10 Jul 2025 17:19:03 +0000, Jack wrote:

    Simulating a coin flip using C++'s <random> header file.


    /*
    * Compile in Visual studio:
    * cl /EHsc /std:c++20 main.cpp */
    #include <iostream>
    #include <random>

    using namespace std;

    int main()
    {
    std::random_device random_device;
    std::mt19937 random_engine{random_device()};
    std::uniform_int_distribution<int> distribution{0, 1};

    int heads = 0; int tails = 0;

    for (int p = 0; p < 10000; p++)
    {
    int coinFlip = distribution(random_engine);

    if (coinFlip == 0)
    heads++;
    else
    tails++;
    }

    cout << "Heads: " << heads << " Tails: " << tails << endl; cout <<
    "Heads: " << (double)heads*100/10000 << "% Tails: " << (double)tails*100/10000 << "%" << endl;
    }
    /*
    * Typical output:
    * Heads: 5066 Tails: 4934 * Heads: 50.66% Tails: 49.34%
    */

    std::mt19937 is not cryptograhically secure, don't use it.

    /Flibble

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: Eweka Internet Services (3:633/280.2@fidonet)
  • From Scott Lurndal@3:633/280.2 to All on Fri Jul 11 04:25:46 2025
    Reply-To: slp53@pacbell.net

    Mr Flibble <flibble@red-dwarf.jmc.corp> writes:
    On Thu, 10 Jul 2025 17:19:03 +0000, Jack wrote:

    Simulating a coin flip using C++'s <random> header file.


    /*
    * Compile in Visual studio:
    * cl /EHsc /std:c++20 main.cpp */
    #include <iostream>
    #include <random>

    using namespace std;

    int main()
    {
    std::random_device random_device;
    std::mt19937 random_engine{random_device()};
    std::uniform_int_distribution<int> distribution{0, 1};

    int heads = 0; int tails = 0;

    for (int p = 0; p < 10000; p++)
    {
    int coinFlip = distribution(random_engine);

    if (coinFlip == 0)
    heads++;
    else
    tails++;
    }

    cout << "Heads: " << heads << " Tails: " << tails << endl; cout <<
    "Heads: " << (double)heads*100/10000 << "% Tails: " <<
    (double)tails*100/10000 << "%" << endl;
    }
    /*
    * Typical output:
    * Heads: 5066 Tails: 4934 * Heads: 50.66% Tails: 49.34%
    */

    std::mt19937 is not cryptograhically secure, don't use it.

    It's perfectly suitable for flipping a coin, which cannot
    by any stretch be considered "cryptography".



    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: UsenetServer - www.usenetserver.com (3:633/280.2@fidonet)
  • From Mr Flibble@3:633/280.2 to All on Sat Jul 12 21:49:22 2025
    On Thu, 10 Jul 2025 18:25:46 +0000, Scott Lurndal wrote:

    Mr Flibble <flibble@red-dwarf.jmc.corp> writes:
    On Thu, 10 Jul 2025 17:19:03 +0000, Jack wrote:

    Simulating a coin flip using C++'s <random> header file.


    /*
    * Compile in Visual studio:
    * cl /EHsc /std:c++20 main.cpp */
    #include <iostream>
    #include <random>

    using namespace std;

    int main()
    {
    std::random_device random_device;
    std::mt19937 random_engine{random_device()};
    std::uniform_int_distribution<int> distribution{0, 1};

    int heads = 0; int tails = 0;

    for (int p = 0; p < 10000; p++)
    {
    int coinFlip = distribution(random_engine);

    if (coinFlip == 0)
    heads++;
    else
    tails++;
    }

    cout << "Heads: " << heads << " Tails: " << tails << endl; cout
    <<
    "Heads: " << (double)heads*100/10000 << "% Tails: " <<
    (double)tails*100/10000 << "%" << endl;
    }
    /*
    * Typical output:
    * Heads: 5066 Tails: 4934 * Heads: 50.66% Tails: 49.34% */

    std::mt19937 is not cryptograhically secure, don't use it.

    It's perfectly suitable for flipping a coin, which cannot by any stretch
    be considered "cryptography".

    No it isn't.

    /Flibble

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: Eweka Internet Services (3:633/280.2@fidonet)
  • From Muttley@DastardlyHQ.org@3:633/280.2 to All on Sun Jul 13 17:50:52 2025
    On Sat, 12 Jul 2025 11:49:22 GMT
    Mr Flibble <flibble@red-dwarf.jmc.corp> wibbled:
    On Thu, 10 Jul 2025 18:25:46 +0000, Scott Lurndal wrote:

    Mr Flibble <flibble@red-dwarf.jmc.corp> writes:
    On Thu, 10 Jul 2025 17:19:03 +0000, Jack wrote:

    Simulating a coin flip using C++'s <random> header file.


    /*
    * Compile in Visual studio:
    * cl /EHsc /std:c++20 main.cpp */
    #include <iostream>
    #include <random>

    using namespace std;

    int main()
    {
    std::random_device random_device;
    std::mt19937 random_engine{random_device()};
    std::uniform_int_distribution<int> distribution{0, 1};

    int heads = 0; int tails = 0;

    for (int p = 0; p < 10000; p++)
    {
    int coinFlip = distribution(random_engine);

    if (coinFlip == 0)
    heads++;
    else
    tails++;
    }

    cout << "Heads: " << heads << " Tails: " << tails << endl; cout
    <<
    "Heads: " << (double)heads*100/10000 << "% Tails: " <<
    (double)tails*100/10000 << "%" << endl;
    }
    /*
    * Typical output:
    * Heads: 5066 Tails: 4934 * Heads: 50.66% Tails: 49.34% */

    std::mt19937 is not cryptograhically secure, don't use it.

    It's perfectly suitable for flipping a coin, which cannot by any stretch
    be considered "cryptography".

    No it isn't.

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux then
    you can do worse than use /dev/urandom or even better /dev/hwrng which uses
    the hardware rng on the CPU though for some reason seems to be root access only. Wierd.


    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Bonita Montero@3:633/280.2 to All on Sun Jul 13 18:29:24 2025
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux then
    you can do worse than use /dev/urandom or even better /dev/hwrng which uses the hardware rng on the CPU though for some reason seems to be root access only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same
    instructions you could access in userspace (RDRAND) without any
    restrictions.


    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Muttley@DastardlyHQ.org@3:633/280.2 to All on Sun Jul 13 18:57:27 2025
    On Sun, 13 Jul 2025 10:29:24 +0200
    Bonita Montero <Bonita.Montero@gmail.com> wibbled:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux then
    you can do worse than use /dev/urandom or even better /dev/hwrng which uses >> the hardware rng on the CPU though for some reason seems to be root access >> only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same

    No idea, seems odd. Maybe its just the way its set up on the machine I have access to right now. I'll check on other distros when I get a chance.



    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From David Brown@3:633/280.2 to All on Sun Jul 13 22:32:24 2025
    On 13/07/2025 10:29, Bonita Montero wrote:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux then
    you can do worse than use /dev/urandom or even better /dev/hwrng which
    uses
    the hardware rng on the CPU though for some reason seems to be root
    access
    only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same instructions you could access in userspace (RDRAND) without any
    restrictions.


    Your guess may or may not be correct - there can be many hardware RNGs,
    many of which are much better than cpu instructions. And on systems
    that use something else for their hardware RNG, root-only access (by
    default) makes sense.

    It may also be to discourage the use of such devices or cpu instructions
    for code that needs cryptographically secure random sources. The
    quality of CPU instruction random numbers has varied significantly
    through the ages, and you'd be nave to rely on it directly.
    /dev/urandom is a better choice for almost anything involving security.

    For coin-tossing, however, pretty much any reasonable pseudo-RNG will be
    fine.



    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Bonita Montero@3:633/280.2 to All on Sun Jul 13 23:22:39 2025
    Am 13.07.2025 um 14:32 schrieb David Brown:
    On 13/07/2025 10:29, Bonita Montero wrote:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux
    then
    you can do worse than use /dev/urandom or even better /dev/hwrng
    which uses
    the hardware rng on the CPU though for some reason seems to be root
    access
    only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same
    instructions you could access in userspace (RDRAND) without any
    restrictions.


    Your guess may or may not be correct - there can be many hardware RNGs,
    many of which are much better than cpu instructions. And on systems
    that use something else for their hardware RNG, root-only access (by default) makes sense.

    It may also be to discourage the use of such devices or cpu instructions
    for code that needs cryptographically secure random sources. The
    quality of CPU instruction random numbers has varied significantly
    through the ages, and you'd be nave to rely on it directly. /dev/
    urandom is a better choice for almost anything involving security.

    So why is /dev/urandom accessible for anyone if it has comparable
    quality ?

    For coin-tossing, however, pretty much any reasonable pseudo-RNG will be fine.




    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Muttley@DastardlyHQ.org@3:633/280.2 to All on Mon Jul 14 00:59:38 2025
    On Sun, 13 Jul 2025 14:32:24 +0200
    David Brown <david.brown@hesbynett.no> wibbled:
    that use something else for their hardware RNG, root-only access (by >default) makes sense.
    It may also be to discourage the use of such devices or cpu instructions
    for code that needs cryptographically secure random sources. The
    quality of CPU instruction random numbers has varied significantly
    through the ages, and you'd be naïve to rely on it directly.
    /dev/urandom is a better choice for almost anything involving security.

    urandom is most definately not as secure as hwrng as its purely software
    driven with all the issues that entails.


    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From Scott Lurndal@3:633/280.2 to All on Mon Jul 14 01:19:20 2025
    Reply-To: slp53@pacbell.net

    Muttley@DastardlyHQ.org writes:
    On Sun, 13 Jul 2025 10:29:24 +0200
    Bonita Montero <Bonita.Montero@gmail.com> wibbled:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux then >>> you can do worse than use /dev/urandom or even better /dev/hwrng which uses >>> the hardware rng on the CPU though for some reason seems to be root access >>> only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same

    No idea, seems odd. Maybe its just the way its set up on the machine I have >access to right now. I'll check on other distros when I get a chance.


    the rngd daemon reads /dev/hwrng which provides entropy for
    the rngd which provides data to /dev/urandom and /dev/random
    (which augment the HW entropy with kernel entropy). Applications
    should use /dev/urandom or /dev/random.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: UsenetServer - www.usenetserver.com (3:633/280.2@fidonet)
  • From Scott Lurndal@3:633/280.2 to All on Mon Jul 14 01:21:22 2025
    Reply-To: slp53@pacbell.net

    Bonita Montero <Bonita.Montero@gmail.com> writes:
    Am 13.07.2025 um 14:32 schrieb David Brown:
    On 13/07/2025 10:29, Bonita Montero wrote:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux
    then
    you can do worse than use /dev/urandom or even better /dev/hwrng
    which uses
    the hardware rng on the CPU though for some reason seems to be root
    access
    only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same
    instructions you could access in userspace (RDRAND) without any
    restrictions.


    Your guess may or may not be correct - there can be many hardware RNGs,
    many of which are much better than cpu instructions.  And on systems
    that use something else for their hardware RNG, root-only access (by
    default) makes sense.

    It may also be to discourage the use of such devices or cpu instructions
    for code that needs cryptographically secure random sources.  The
    quality of CPU instruction random numbers has varied significantly
    through the ages, and you'd be naïve to rely on it directly. /dev/
    urandom is a better choice for almost anything involving security.

    So why is /dev/urandom accessible for anyone if it has comparable
    quality ?

    1) /dev/urandom has been the go-to source for random numbers in linux
    for decades. Its output is derived from both hardware entropy and
    the kernel entropy pool.

    2) See prior reply vis-a-vis /dev/hwrng and rngd(1m).

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: UsenetServer - www.usenetserver.com (3:633/280.2@fidonet)
  • From Scott Lurndal@3:633/280.2 to All on Mon Jul 14 01:22:27 2025
    Reply-To: slp53@pacbell.net

    Muttley@DastardlyHQ.org writes:
    On Sun, 13 Jul 2025 14:32:24 +0200
    David Brown <david.brown@hesbynett.no> wibbled:
    that use something else for their hardware RNG, root-only access (by >>default) makes sense.
    It may also be to discourage the use of such devices or cpu instructions >>for code that needs cryptographically secure random sources. The
    quality of CPU instruction random numbers has varied significantly
    through the ages, and you'd be naïve to rely on it directly.
    /dev/urandom is a better choice for almost anything involving security.

    urandom is most definately not as secure as hwrng as its purely software >driven with all the issues that entails.

    That is not the case. urandom output is derived from multiple entropy
    pools, including hwrng if available.

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: UsenetServer - www.usenetserver.com (3:633/280.2@fidonet)
  • From Chris M. Thomasson@3:633/280.2 to All on Mon Jul 14 05:56:50 2025
    On 7/13/2025 8:19 AM, Scott Lurndal wrote:
    Muttley@DastardlyHQ.org writes:
    On Sun, 13 Jul 2025 10:29:24 +0200
    Bonita Montero <Bonita.Montero@gmail.com> wibbled:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux then >>>> you can do worse than use /dev/urandom or even better /dev/hwrng which uses
    the hardware rng on the CPU though for some reason seems to be root access >>>> only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same

    No idea, seems odd. Maybe its just the way its set up on the machine I have >> access to right now. I'll check on other distros when I get a chance.


    the rngd daemon reads /dev/hwrng which provides entropy for
    the rngd which provides data to /dev/urandom and /dev/random
    (which augment the HW entropy with kernel entropy). Applications
    should use /dev/urandom or /dev/random.

    Fwiw, on a side note, check this shit out:

    (A funny race-condition based RNG...) https://groups.google.com/g/comp.lang.c++/c/7u_rLgQe86k/m/fYU9SnuAFQAJ

    ;^)

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From David Brown@3:633/280.2 to All on Tue Jul 15 00:06:12 2025
    On 13/07/2025 15:22, Bonita Montero wrote:
    Am 13.07.2025 um 14:32 schrieb David Brown:
    On 13/07/2025 10:29, Bonita Montero wrote:
    Am 13.07.2025 um 09:50 schrieb Muttley@DastardlyHQ.org:

    random() % 2 after a suitable seed is sufficient for coin flipping.

    If you're really fussed about random number generation and use linux
    then
    you can do worse than use /dev/urandom or even better /dev/hwrng
    which uses
    the hardware rng on the CPU though for some reason seems to be root
    access
    only. Wierd.

    Why is /dev/hwrng root-only ? I guess on x86 it bases on the same
    instructions you could access in userspace (RDRAND) without any
    restrictions.


    Your guess may or may not be correct - there can be many hardware
    RNGs, many of which are much better than cpu instructions. And on
    systems that use something else for their hardware RNG, root-only
    access (by default) makes sense.

    It may also be to discourage the use of such devices or cpu
    instructions for code that needs cryptographically secure random
    sources. The quality of CPU instruction random numbers has varied
    significantly through the ages, and you'd be nave to rely on it
    directly. /dev/ urandom is a better choice for almost anything
    involving security.

    So why is /dev/urandom accessible for anyone if it has comparable
    quality ?


    /dev/urandom provides a higher quality source of random numbers than
    most hardware random number generators - especially the simplistic ones
    found in some cpus. It is also documented (with the source available, obviously), and analysed by independent experts - unlike cpu random
    number generators which could be buggy, have unexpected biases or uneven distributions, or even be compromised with backdoors or predictable
    sequences (extreme paranoia is a virtue for cryptographers).

    (Muttley is wrong to suggest that /dev/hwrng is better than
    /dev/urandom, in almost all situations.)



    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From David Brown@3:633/280.2 to All on Tue Jul 15 00:19:15 2025
    On 13/07/2025 16:59, Muttley@DastardlyHQ.org wrote:
    On Sun, 13 Jul 2025 14:32:24 +0200
    David Brown <david.brown@hesbynett.no> wibbled:
    that use something else for their hardware RNG, root-only access (by
    default) makes sense.
    It may also be to discourage the use of such devices or cpu instructions
    for code that needs cryptographically secure random sources. The
    quality of CPU instruction random numbers has varied significantly
    through the ages, and you'd be nave to rely on it directly.
    /dev/urandom is a better choice for almost anything involving security.

    urandom is most definately not as secure as hwrng as its purely software driven with all the issues that entails.


    No.

    /dev/hwrng gets its values from some kind of hardware random number
    generator. Some hardware number generators are good, some are bad.
    Some have poor distributions that are hard to use well. Some have
    questions about their security. Some are very slow.

    /dev/urandom makes use of /dev/hwrng as a source of entropy for seeding
    a high quality pseudo random number generator. It also uses other
    entropy sources such as timing of network packets or user interaction, temperature fluctuations, and so on. This makes it immune to any risk
    of backdoors or deliberately poor randomness. The PRNG algorithms have clearer and smoother distributions - while keeping the entropy that the
    system gets in. (If you pull vast amounts out of /dev/urandom, in
    relation to the entropy it gets, you will reduce the quality of randomness.)

    And of course the source for /dev/urandom is there for anyone to see and analyse, unlike the black boxes of hardware random number generators.




    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)
  • From candycanearter07@3:633/280.2 to All on Tue Jul 15 01:10:02 2025
    Scott Lurndal <scott@slp53.sl.home> wrote at 15:22 this Sunday (GMT):
    Muttley@DastardlyHQ.org writes:
    On Sun, 13 Jul 2025 14:32:24 +0200
    David Brown <david.brown@hesbynett.no> wibbled:
    that use something else for their hardware RNG, root-only access (by >>>default) makes sense.
    It may also be to discourage the use of such devices or cpu instructions >>>for code that needs cryptographically secure random sources. The >>>quality of CPU instruction random numbers has varied significantly >>>through the ages, and you'd be nave to rely on it directly. >>>/dev/urandom is a better choice for almost anything involving security.

    urandom is most definately not as secure as hwrng as its purely software >>driven with all the issues that entails.

    That is not the case. urandom output is derived from multiple entropy pools, including hwrng if available.


    If you're that worried, you can use a third party library on top of
    that.
    --
    user <candycane> is generated from /dev/urandom

    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: the-candyden-of-code (3:633/280.2@fidonet)
  • From Bonita Montero@3:633/280.2 to All on Tue Jul 15 01:38:27 2025
    Am 14.07.2025 um 16:06 schrieb David Brown:

    /dev/urandom provides a higher quality source of random numbers than
    most hardware random number generators - especially the simplistic ones found in some cpus. It is also documented (with the source available, obviously), and analysed by independent experts - unlike cpu random
    number generators which could be buggy, have unexpected biases or uneven distributions, or even be compromised with backdoors or predictable sequences (extreme paranoia is a virtue for cryptographers).

    Show me a source for that regarding RDRAND on x86.


    --- MBSE BBS v1.1.1 (Linux-x86_64)
    * Origin: A noiseless patient Spider (3:633/280.2@fidonet)