MCPcopy Create free account
hub / github.com/ArashPartow/exprtk / randu

Class randu

exprtk_simple_example_19.cpp:29–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28template <typename T>
29class randu : public exprtk::igeneric_function<T>
30{
31public:
32
33 typedef typename exprtk::igeneric_function<T> igfun_t;
34 typedef typename igfun_t::parameter_list_t parameter_list_t;
35 typedef typename igfun_t::generic_type generic_type;
36 typedef typename generic_type::vector_view vector_t;
37
38 using exprtk::igeneric_function<T>::operator();
39
40 randu()
41 : exprtk::igeneric_function<T>("V|VTT")
42 /*
43 Overloads:
44 0. V - vector
45 1. VTT - vector, r0, r1
46 */
47 { ::srand(static_cast<unsigned int>(time(NULL))); }
48
49 inline T operator()(const std::size_t& ps_index, parameter_list_t parameters)
50 {
51 vector_t v(parameters[0]);
52
53 std::size_t r0 = 0;
54 std::size_t r1 = v.size() - 1;
55
56 using namespace exprtk::rtl::vecops::helper;
57
58 if (
59 (1 == ps_index) &&
60 !load_vector_range<T>::process(parameters, r0, r1, 1, 2, 0)
61 )
62 return T(0);
63
64 for (std::size_t i = r0; i <= r1; ++i)
65 {
66 v[i] = rnd();
67 }
68
69 return T(1);
70 }
71
72private:
73
74 inline T rnd()
75 {
76 // Note: Do not use this in production
77 // Result is in the interval [0,1)
78 return T(::rand() / T(RAND_MAX + 1.0));
79 }
80};
81
82template <typename T>
83void vector_randu()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected