Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
(defn rand-between [a b]
(+ a (* (- b a) (rand))))
defmodule MyRandomPicker do
def pick(a, b), do: a + (b - a) * :rand.uniform()
end
a + :rand.uniform() * (b-a)
A + (B - A) * rand:uniform().
call random_number(c)
d = a + (b-a) * c
pick(a,b)=
return.(+a).(*(b-a))=<<System.Random.randomIO::IO(Double)
pick a b = do
r <- System.Random.randomIO :: IO Double
return a + (r * (b - a))
a + (b-a) * Math.random();
a + Math.random() * (b - a)
(+ a (random (float (- b a))))
function pick(a,b)
return a + (math.random()*(b-a))
end
function pick(float $a, float $b): float
{
$rand = mt_rand() / mt_getrandmax();
$rand *= ($b - $a);
$rand += ($a);
return $rand;
}
function pick(a, b:real): real;
begin
result := a + random * (b - a);
end;
my ($min, $max) = (1.5, 7.2);
my $x = $min + rand($max-$min);
rand(a...b)
(+ a (* (- b a) (random 1.0)))
| rand |
rand := Random new.
rand next * (b - a) + a