From: already5chosen@yahoo.com   
      
   On Mon, 22 Dec 2025 22:57:27 +0100   
   Janis Papanagnou wrote:   
      
   > On 2025-12-22 19:45, Michael S wrote:   
   > > [...] LFSR is a reasonably good PRNG for a single bit, but   
   > > not when you want to generate a group of 31 pseudo-random bits. In   
   > > order to get 31 new bits, without predictable repetitions from the   
   > > previous value, you would have to do 31 steps. That's slow! The   
   > > process can be accelerate by generation of several bits at time via   
   > > look up tables, but in order to get decent speed the table has to   
   > > be rater big and using big tables in standard library is bad   
   > > sportsmanship.   
   >   
   > Yes. But mind that the speed is also depending on what quality you   
   > need. For example; I used the PN-generator to create bit-sequences   
   > (as you also suggest). For another application both, PN-LFSR and   
   > LCG (that you mention below), were inacceptable; we used a cipher   
   > to create the random data. (If you compare the speed of creating   
   > the cipher to a bit-shift-register the latter looks really fast.)   
   >   
   > >   
   > > It seems that overwhelming majority C RTLs use Linear Congruential   
   > > Generators, probably because for Stanadard library compactness of   
   > > both code and data is considered more important than very high   
   > > speed (not that on modern HW LCGs are slow) or superior random   
   > > properties of Mersenne Twisters.   
   >   
   > For "standard applications" I always used the simple LCGs; simple   
   > and fast. Or whatever the tools or library provided; which were   
   > mostly anyway LCGs.   
   >   
   > Janis   
   >   
   > > [...]   
   >   
      
   When I need PRNG then I am typically not deeply concerned about size of   
   its internal state. On the other hand, I don't want to care about   
   potentially insufficient randomness of the output (not in crypto   
   sense). On the 3rd hand, vectors that I generate with PRNG tend to be   
   big and I don't like to wait, so I do care somewhat about speed.   
   Those 3 factors together plus availability long ago made MT19937-64   
   into my personal default PRNG of choice.   
      
   MT19937-64 is available out of the box(*) in C++. But not in C,   
   unfortunately.   
      
   At higher theoretical level MT is a generalization of LFSR, but it is   
   not obvious when one looks at implementation.   
      
   ---------   
   * - hidden behind unnecessary levels of abstraction that just make it   
    harder to use, but that's another story.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|