foundations of randomness
parent
dabe142e0b
commit
c9d1aaa89c
|
@ -1,5 +1,5 @@
|
||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(lilfbtf5 VERSION 0.1.14)
|
project(lilfbtf5 VERSION 0.1.15)
|
||||||
|
|
||||||
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
|
||||||
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LILFBTF5_RANDOM_H
|
||||||
|
#define LILFBTF5_RANDOM_H
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
#include <blt/std/types.h>
|
||||||
|
|
||||||
|
namespace fb
|
||||||
|
{
|
||||||
|
class random
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
blt::u64 seed;
|
||||||
|
std::mt19937_64 engine;
|
||||||
|
public:
|
||||||
|
explicit random(blt::u64 seed);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
bool choice();
|
||||||
|
|
||||||
|
float random_float(float min = 0, float max = 1);
|
||||||
|
double random_double(double min = 0, double max = 1);
|
||||||
|
blt::u64 random_long(blt::u64 min = 0, blt::u64 max = 1);
|
||||||
|
blt::i32 random_int(blt::i32 min = 0, blt::i32 max = 1);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //LILFBTF5_RANDOM_H
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LILFBTF5_TREE_H
|
||||||
|
#define LILFBTF5_TREE_H
|
||||||
|
|
||||||
|
namespace fb
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //LILFBTF5_TREE_H
|
2
libs/BLT
2
libs/BLT
|
@ -1 +1 @@
|
||||||
Subproject commit 1abd3214be23289b26f4cf2329c4a58c0c7be04b
|
Subproject commit 9bba525b1f33495a68c43fa1f66c0a239220e68c
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <lilfbtf/random.h>
|
||||||
|
|
||||||
|
namespace fb
|
||||||
|
{
|
||||||
|
|
||||||
|
random::random(blt::u64 seed): seed(seed), engine(seed)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void random::reset()
|
||||||
|
{
|
||||||
|
engine.seed(seed);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool random::choice()
|
||||||
|
{
|
||||||
|
static std::uniform_int_distribution<int> dist(0, 1);
|
||||||
|
return dist(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
float random::random_float(float min, float max)
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<float> dist(min, max);
|
||||||
|
return dist(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
double random::random_double(double min, double max)
|
||||||
|
{
|
||||||
|
std::uniform_real_distribution<double> dist(min, max);\
|
||||||
|
return dist(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
blt::u64 random::random_long(blt::u64 min, blt::u64 max)
|
||||||
|
{
|
||||||
|
std::uniform_int_distribution<blt::u64> dist(min, max);
|
||||||
|
return dist(engine);
|
||||||
|
}
|
||||||
|
|
||||||
|
blt::i32 random::random_int(blt::i32 min, blt::i32 max)
|
||||||
|
{
|
||||||
|
std::uniform_int_distribution<blt::i32> dist(min, max);
|
||||||
|
return dist(engine);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <lilfbtf/tree.h>
|
||||||
|
|
||||||
|
namespace fb
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LILFBTF5_TEST5_H
|
||||||
|
#define LILFBTF5_TEST5_H
|
||||||
|
|
||||||
|
namespace fb
|
||||||
|
{
|
||||||
|
void test5();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //LILFBTF5_TEST5_H
|
|
@ -7,6 +7,7 @@
|
||||||
#include <lilfbtf/test3.h>
|
#include <lilfbtf/test3.h>
|
||||||
#include <lilfbtf/test4.h>
|
#include <lilfbtf/test4.h>
|
||||||
#include "blt/profiling/profiler_v2.h"
|
#include "blt/profiling/profiler_v2.h"
|
||||||
|
#include "lilfbtf/test5.h"
|
||||||
|
|
||||||
struct data {
|
struct data {
|
||||||
float f;
|
float f;
|
||||||
|
@ -50,7 +51,8 @@ int main(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
//fb::test2();
|
//fb::test2();
|
||||||
//fb::test3();
|
//fb::test3();
|
||||||
fb::test4();
|
//fb::test4();
|
||||||
|
fb::test5();
|
||||||
|
|
||||||
BLT_PRINT_PROFILE("Tree Construction");
|
BLT_PRINT_PROFILE("Tree Construction");
|
||||||
BLT_PRINT_PROFILE("Tree Evaluation");
|
BLT_PRINT_PROFILE("Tree Evaluation");
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 Brett Terpstra
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <blt/std/any.h>
|
||||||
|
#include <blt/std/logging.h>
|
||||||
|
#include <lilfbtf/test5.h>
|
||||||
|
|
||||||
|
namespace fb
|
||||||
|
{
|
||||||
|
|
||||||
|
struct destoryable
|
||||||
|
{
|
||||||
|
std::string name;
|
||||||
|
destoryable(std::string_view name): name(name)
|
||||||
|
{
|
||||||
|
BLT_INFO("Called constructor %s", this->name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
~destoryable()
|
||||||
|
{
|
||||||
|
BLT_INFO("Called destructor %s", name.c_str());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void test5()
|
||||||
|
{
|
||||||
|
blt::unsafe::any_t_union any_construct(destoryable{"construct"});
|
||||||
|
|
||||||
|
blt::unsafe::any_t_union any_assignment = 5;
|
||||||
|
|
||||||
|
any_assignment = destoryable{"assignment"};
|
||||||
|
|
||||||
|
any_construct = destoryable{"copy"};
|
||||||
|
|
||||||
|
// copy
|
||||||
|
any_assignment = any_construct;
|
||||||
|
|
||||||
|
any_assignment = destoryable{"move"};
|
||||||
|
|
||||||
|
any_construct = std::move(any_assignment);
|
||||||
|
|
||||||
|
any_assignment = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue