Files
openharmony-mlx/gpt_oss/metal/source/include/internal/rng.hpp
Dominik Kundel 243a1b0276 Initial commit
Co-authored-by: Zhuohan Li <zhuohan@openai.com>
Co-authored-by: Maratyszcza <marat@openai.com>
Co-authored-by: Volodymyr Kyrylov <vol@wilab.org.ua>
2025-08-05 08:19:49 -07:00

33 lines
583 B
C++

#pragma once
#include <cstdint>
namespace gptoss {
namespace rng {
inline static std::uint32_t squares32(std::uint64_t offset, std::uint64_t seed) {
const std::uint64_t y = offset * seed;
const std::uint64_t z = y + seed;
/* Round 1 */
std::uint64_t x = y * y + y;
x = (x >> 32) | (x << 32);
/* Round 2 */
x = x * x + z;
x = (x >> 32) | (x << 32);
/* Round 3 */
x = x * x + y;
x = (x >> 32) | (x << 32);
/* Round 4 */
x = x * x + z;
return static_cast<uint32_t>(x >> 32);
}
} // namespace rng
} // namespace gptoss