Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c    |    Meh, in C you gotta define EVERYTHING    |    243,242 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 242,604 of 243,242    |
|    BGB to All    |
|    Re: srand(0)    |
|    25 Dec 25 15:29:59    |
      From: cr88192@gmail.com              On 12/25/2025 1:31 PM, Lawrence D’Oliveiro wrote:       > On Thu, 25 Dec 2025 03:07:03 -0600, BGB wrote:       >       >> One entropy-mining process is to use "clock()" or similar and then       >> spin in a loop for a certain amount of time effectively building a       >> hash of the values returned by clock. The exact timing when the       >> values change will tend to carry a certain amount of entropy.       >       > The turbulence of the air/gas inside disk drives is apparently a good       > source of randomness.              Yeah, but one doesn't easily have access to this information.       Likewise to access from the low order bits of CPU thermometers or       similar, etc.              For some of my targets, there is also no HDD (typically, everything runs       off of SD cards).                     FWIW, in my own CPU design, there is actually a hardware RNG where       internal signals are basically gathered up and fed around the bus in a       special noise channel and used to continuously feed into a hardware RNG       for which a value can be read with a special CPU instruction.              But, alas, mainline CPUs lack such a feature.              On x86, it is also possible to get some level of entropy from mining       RDTSC, but this is non-portable.                                   But, yeah, tested out a few more RNG designs, and ATM:        seed1 ^= ~(seed2>>47); seed2 ^= ~(seed1>>43); // 4 cycles        seed1 ^= (seed1<<13); seed2 ^= (seed2>>11); // 4 cycles        seed1 ^= (seed1>>19); seed2 ^= (seed2<<17); // 4 cycles        val = ((seed1 ^ seed2) >> 32) & 0x7FFF; // 6 cycles       Seems to be working pretty OK (decent randomness), and is moderately fast.              Add cost of +4 cycles for LD (2c penalty), +2 ST       Est cost: Around 24 clock cycles.                     Though, breaking up the shifts and xors using temporaries could be used       to micro-optimize it a little more (vs trying to rely on compile-time       instruction shuffling).              Downside as that this particular approach (XOR'ing values with       themselves and modifying the original variable before the next step),       creates a lot of dependencies which limits the potential ILP (can't get       ILP over 2 in this case).              Where, the interleaved "seed1 = (seed1< |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca