medfall

A super great game engine
Log | Files | Refs

pcg.h (1404B)


      1 /*
      2  * PCG Random Number Generation for C.
      3  *
      4  * Copyright 2014 Melissa O'Neill <oneill@pcg-random.org>
      5  *
      6  * Licensed under the Apache License, Version 2.0 (the "License");
      7  * you may not use this file except in compliance with the License.
      8  * You may obtain a copy of the License at
      9  *
     10  *     http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  * Unless required by applicable law or agreed to in writing, software
     13  * distributed under the License is distributed on an "AS IS" BASIS,
     14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  * See the License for the specific language governing permissions and
     16  * limitations under the License.
     17  *
     18  * For additional information about the PCG random number generation scheme,
     19  * including its license and other licensing options, visit
     20  *
     21  *     http://www.pcg-random.org
     22  */
     23 
     24 /*
     25  * This code is derived from the full C implementation, which is in turn
     26  * derived from the canonical C++ PCG implementation. The C++ version
     27  * has many additional features and is preferable if you can use C++ in
     28  * your project.
     29  */
     30 
     31 #pragma once
     32 
     33 #include "intrinsics.h"
     34 #include "rng/rng_utils.h"
     35 
     36 struct PCG {
     37 	u64 state; // RNG state.  All values are possible.
     38 	u64 inc;   // Controls which RNG sequence (stream) is
     39                    // selected. Must *always* be odd.
     40 };
     41 
     42 PCG new_pcg();
     43 PCG new_pcg( u64 state, u64 seq );
     44 
     45 u32 rng_next( PCG * pcg );