medfall

A super great game engine
Log | Files | Refs

fixed.cc (655B)


      1 /*
      2  * implementation of a lookup table PRNG
      3  *
      4  * the table is generated by sampling WELL512, so it has the same properties,
      5  * except the period is much lower
      6  *
      7  * on my laptop, WELL512 takes 1.2s to generate 10m numbers and this takes 0.8s
      8  * the speed and badness make it viable for particle systems and not much else
      9  */
     10 
     11 #include "intrinsics.h"
     12 #include "rng/fixed.h"
     13 
     14 static u32 nums[] = {
     15 #include "rng/fixed_lookup.h"
     16 };
     17 
     18 FixedRNG new_fixed_rng( u16 index ) {
     19 	FixedRNG rng;
     20 	rng.index = index;
     21 	return rng;
     22 }
     23 
     24 u32 rng_next( FixedRNG * rng ) {
     25 	u32 ret = nums[ rng->index ];
     26 	rng->index = ( rng->index + 1 ) % ARRAY_COUNT( nums );
     27 	return ret;
     28 }