diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-03-24 00:11:28 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-03-29 22:18:48 +0200 |
commit | 866b09992668f97af063dcd77dc5dd0e3a512b94 (patch) | |
tree | dfeffaa3eb1a559d746d04f3fbb7402e74d1b290 /src/instrument.cc | |
parent | efe93864d53f72be4fa4dfe003f0f7578fc558e2 (diff) |
New Random class for convenient random number generation.
Diffstat (limited to 'src/instrument.cc')
-rw-r--r-- | src/instrument.cc | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/instrument.cc b/src/instrument.cc index 96a6bfd..21371f0 100644 --- a/src/instrument.cc +++ b/src/instrument.cc @@ -70,9 +70,8 @@ Sample *Instrument::sample(level_t level, size_t pos) } if(Conf::enable_velocity_randomiser) { - float r = (float)rand() / (float)RAND_MAX; // random number: [0;1] - r -= 0.5; // random number [-0.5;0.5] - r *= Conf::velocity_randomiser_weight * 2; // ex. random number [-0.1;0.1] + float r = rand.floatInRange(-1.0*Conf::velocity_randomiser_weight, + Conf::velocity_randomiser_weight); level += r; if(level > 1.0) level = 1.0; if(level < 0.0) level = 0.0; @@ -91,8 +90,7 @@ Sample *Instrument::sample(level_t level, size_t pos) // Version 1.0 std::vector<Sample*> s = samples.get(level * mod); if(s.size() == 0) return NULL; - size_t idx = rand()%(s.size()); - sample = s[idx]; + sample = rand.choose(s); } if(Conf::enable_velocity_modifier) { |