OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
rand_float.hpp
1#pragma once
2#include <ossia/dataflow/graph_node.hpp>
3#include <ossia/dataflow/port.hpp>
4
5#include <random>
6
7namespace ossia::nodes
8{
9struct rand_float final : public ossia::nonowning_graph_node
10{
11 ossia::value_outlet value_out;
12
13public:
14 std::uniform_real_distribution<float> dist;
15 rand_float(float min, float max)
16 : dist{min, max}
17 {
18 m_outlets.push_back(&value_out);
19 }
20
21 std::string label() const noexcept override { return "rand_float"; }
22 void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
23 {
24 auto& out = *value_out.target<ossia::value_port>();
25 auto tm = e.timings(t);
26#if defined(OSSIA_FREESTANDING)
27 out.write_value((rand() - dist.a()) / (dist.b() - dist.a()), tm.start_sample);
28#else
29 thread_local std::mt19937 gen;
30 out.write_value(dist(gen), tm.start_sample);
31#endif
32 }
33};
34}
OSSIA_INLINE constexpr auto min(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
min function tailored for values
Definition math.hpp:125
OSSIA_INLINE constexpr auto max(const T a, const U b) noexcept -> typename std::conditional<(sizeof(T) > sizeof(U)), T, U >::type
max function tailored for values
Definition math.hpp:96