
.. _program_listing_file_library_include_rocrand_rocrand_scrambled_sobol32.h:

Program Listing for File rocrand_scrambled_sobol32.h
====================================================

|exhale_lsh| :ref:`Return to documentation for file <file_library_include_rocrand_rocrand_scrambled_sobol32.h>` (``library/include/rocrand/rocrand_scrambled_sobol32.h``)

.. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS

.. code-block:: cpp

   // Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
   //
   // Permission is hereby granted, free of charge, to any person obtaining a copy
   // of this software and associated documentation files (the "Software"), to deal
   // in the Software without restriction, including without limitation the rights
   // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   // copies of the Software, and to permit persons to whom the Software is
   // furnished to do so, subject to the following conditions:
   //
   // The above copyright notice and this permission notice shall be included in
   // all copies or substantial portions of the Software.
   //
   // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
   // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   // THE SOFTWARE.
   
   #ifndef ROCRAND_SCRAMBLED_SOBOL32_H_
   #define ROCRAND_SCRAMBLED_SOBOL32_H_
   
   #ifndef FQUALIFIERS
       #define FQUALIFIERS __forceinline__ __device__
   #endif // FQUALIFIERS_
   
   #include "rocrand/rocrand_common.h"
   #include "rocrand/rocrand_sobol32.h"
   
   namespace rocrand_device
   {
   
   template<bool UseSharedVectors>
   class scrambled_sobol32_engine
   {
   public:
       FQUALIFIERS
       scrambled_sobol32_engine() {}
   
       FQUALIFIERS
       scrambled_sobol32_engine(const unsigned int* vectors,
                                const unsigned int  scramble_constant,
                                const unsigned int  offset)
           : m_engine(vectors, 0), scramble_constant(scramble_constant)
       {
           discard(offset);
       }
   
       FQUALIFIERS
       void discard(unsigned int offset)
       {
           m_engine.discard(offset);
       }
   
       FQUALIFIERS
       void discard()
       {
           m_engine.discard();
       }
   
       FQUALIFIERS
       void discard_stride(unsigned int stride)
       {
           m_engine.discard_stride(stride);
       }
   
       FQUALIFIERS
       unsigned int operator()()
       {
           return this->next();
       }
   
       FQUALIFIERS
       unsigned int next()
       {
           unsigned int p = m_engine.next();
           return p ^ scramble_constant;
       }
   
       FQUALIFIERS
       unsigned int current()
       {
           unsigned int p = m_engine.current();
           return p ^ scramble_constant;
       }
   
   protected:
       // Underlying sobol32 engine
       sobol32_engine<UseSharedVectors> m_engine;
       // scrambling constant
       unsigned int scramble_constant;
   
   }; // scrambled_sobol32_engine class
   
   } // end namespace rocrand_device
   
   typedef rocrand_device::scrambled_sobol32_engine<false> rocrand_state_scrambled_sobol32;
   
   FQUALIFIERS
   void rocrand_init(const unsigned int*              vectors,
                     const unsigned int               scramble_constant,
                     const unsigned int               offset,
                     rocrand_state_scrambled_sobol32* state)
   {
       *state = rocrand_state_scrambled_sobol32(vectors, scramble_constant, offset);
   }
   
   FQUALIFIERS
   unsigned int rocrand(rocrand_state_scrambled_sobol32* state)
   {
       return state->next();
   }
   
   FQUALIFIERS
   void skipahead(unsigned long long offset, rocrand_state_scrambled_sobol32* state)
   {
       return state->discard(offset);
   }
   
    // end of group rocranddevice
   #endif // ROCRAND_SCRAMBLED_SOBOL32_H_
