rand: prefer our own generators
This commit is contained in:
parent
5f4c95aa11
commit
34270e5b8f
@ -478,6 +478,7 @@ list (
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/prefix/${PREFIX}/preprocessor.hpp"
|
||||
quaternion.cpp
|
||||
quaternion.hpp
|
||||
rand/generic.hpp
|
||||
rand/lcg.cpp
|
||||
rand/lcg.hpp
|
||||
rand/mwc64x.cpp
|
||||
|
18
rand/generic.hpp
Normal file
18
rand/generic.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* Copyright 2020, Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xoshiro.hpp"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace cruft::rand {
|
||||
/// A generator with a good tradeoff between speed, size, and quality.
|
||||
using general_generator = xoshiro256plusplus;
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "coord/traits.hpp"
|
||||
#include "rand/generic.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@ -54,7 +55,7 @@ namespace cruft::random {
|
||||
inline auto&
|
||||
generator (void)
|
||||
{
|
||||
using generator_t = std::mt19937_64;
|
||||
using generator_t = cruft::rand::general_generator;
|
||||
static thread_local auto gen = initialise<generator_t> ();
|
||||
return gen;
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include "geom/sample/edge.hpp"
|
||||
#include "tap.hpp"
|
||||
#include "coord/iostream.hpp"
|
||||
#include "coord/comparator.hpp"
|
||||
#include "coord/iostream.hpp"
|
||||
#include "geom/sample/edge.hpp"
|
||||
#include "rand/generic.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
@ -14,7 +15,7 @@ int main ()
|
||||
std::map<cruft::point2i, int, cruft::coord::ordering<>> counts;
|
||||
|
||||
auto sampler = cruft::geom::sample::edge (AREA);
|
||||
std::mt19937_64 gen;
|
||||
cruft::rand::general_generator gen (42);
|
||||
|
||||
cruft::TAP::logger tap;
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "list/sort.hpp"
|
||||
#include "random.hpp"
|
||||
#include "rand/generic.hpp"
|
||||
#include "tap.hpp"
|
||||
#include "iterator/zip.hpp"
|
||||
|
||||
@ -72,7 +73,7 @@ int main ()
|
||||
std::shuffle (
|
||||
std::begin (data),
|
||||
std::end (data),
|
||||
std::mt19937 {COUNT}
|
||||
cruft::rand::general_generator {COUNT}
|
||||
);
|
||||
|
||||
test_sort (tap, std::move (data), "sorting large unique and shuffled array");
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "functor.hpp"
|
||||
#include "geom/aabb.hpp"
|
||||
#include "geom/sample/surface.hpp"
|
||||
#include "rand/generic.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
@ -24,10 +25,12 @@ main (int argc, char **argv)
|
||||
|
||||
opts.scan (argc, argv);
|
||||
|
||||
auto gen = cruft::random::initialise<cruft::rand::general_generator> ();
|
||||
|
||||
std::cout << "<svg height='" << area.h << "' width='" << area.h << "'>";
|
||||
namespace sample = cruft::geom::sample;
|
||||
for (auto const &p: sample::poisson (sample::surface {area},
|
||||
std::default_random_engine (),
|
||||
gen,
|
||||
cruft::functor::constant (distance),
|
||||
samples))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user