libcruft-util/rand/mwc64x.hpp

44 lines
1.2 KiB
C++
Raw Normal View History

2016-06-30 18:15:05 +10:00
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2016 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_RAND_MWC64X_HPP
#define __UTIL_RAND_MWC64X_HPP
#include <cstdint>
2017-01-05 15:06:49 +11:00
namespace util::rand {
2016-06-30 18:15:05 +10:00
// multiply-with-carry style generator suitable for rapid seeking and
// GPU generation.
//
// as with all such style generators, the seed value is very important.
// don't allow either half of the uint64_t to be zero.
struct mwc64x {
public:
using value_type = uint32_t;
using seed_type = uint64_t;
2017-05-23 12:50:51 +10:00
explicit mwc64x (seed_type);
2016-06-30 18:15:05 +10:00
value_type operator() (void);
private:
uint64_t m_state;
};
2017-01-05 15:06:49 +11:00
}
2016-06-30 18:15:05 +10:00
#endif