Started on Random Library
I made seed and uniform functions, but they are not omp friendly. They are runnning omp themself, but is not safe for threading/parallizing. Uniform is aproximated and is NOT validaded up against a real uniform distribution.
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/**++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* PANIC
|
||||
* Portable Algorithms and Numerics In C++
|
||||
*
|
||||
* Scientific computing from scratch, with feeling.
|
||||
*
|
||||
* Copyright (c) 2026 Michelle Bausager
|
||||
*
|
||||
* This file is part of PANIC.
|
||||
*
|
||||
* PANIC is free software licensed under the GNU General Public License v3.0 or later.
|
||||
* You may redistribute and/or modify it under the terms of the GPL.
|
||||
*
|
||||
* PANIC 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 LICENSE file for the full license text.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
*
|
||||
* Project Name: PANIC
|
||||
* Module Name: random
|
||||
* File Name: seed.hpp
|
||||
* Revision: 0.1.0
|
||||
* Date: 28-07-2026
|
||||
* Author: Michelle Bausager
|
||||
*
|
||||
* Description:
|
||||
* Defines seed for use in other functions in random/
|
||||
*
|
||||
*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
||||
#pragma once
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// INCLUDE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
#include <config/types.hpp> // panic::uint_t, panic::int_t, and panic::real_t
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
// Function Name : panic::random::seed
|
||||
//
|
||||
// Description:
|
||||
// base for random libary
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
namespace panic{
|
||||
namespace random{
|
||||
|
||||
/**
|
||||
* @brief struct for seed object used in random/
|
||||
*
|
||||
* The struct is used for PANIC random library.
|
||||
*/
|
||||
struct seed_t{
|
||||
|
||||
// Variable to store the value the random value is based on.
|
||||
panic::types::uint_t value;
|
||||
|
||||
/**
|
||||
* @brief Empthy constructor
|
||||
*
|
||||
*/
|
||||
seed_t();
|
||||
|
||||
/**
|
||||
* @brief Contructor with seed.
|
||||
*
|
||||
* @param seed The seed that is used as the base for the object.
|
||||
*/
|
||||
seed_t(panic::types::uint_t seed);
|
||||
|
||||
/**
|
||||
* @brief Function to set the seed..
|
||||
*
|
||||
* @param seed The seed that is used as the base for the object.
|
||||
*/
|
||||
bool set(panic::types::uint_t seed);
|
||||
|
||||
// Creates a deterministic state from the seed and an index.
|
||||
// This is OMP-friendly because it does not modify shared memory.
|
||||
/**
|
||||
* @brief Returns a random number based on seed and index
|
||||
*
|
||||
* @param index Value the random number will be drawn from.
|
||||
*
|
||||
* @Note this can be used with omp in a loop if the index in the loop
|
||||
* is used as the input to this function.
|
||||
*/
|
||||
panic::types::uint_t state_at(panic::types::uint_t index) const;
|
||||
|
||||
/**
|
||||
* @brief Returns the base seed value.
|
||||
*
|
||||
*/
|
||||
panic::types::uint_t get();
|
||||
};
|
||||
|
||||
|
||||
|
||||
} // namespace random
|
||||
} // namespace panic
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// VARIABLE DESCRIPTION
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
// FUNCTION PROTOTYPE
|
||||
//---------------------------------------------------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user