Adjust algorithm for generating random strength values
By : Hayden Dee
Date : March 29 2020, 07:55 AM
this will help The values 1.033 and 0.45 in the original code are the magic numbers that provide the scale 1.1  9.9. You should get the same results if you pass in 1.1 and 9.9 as the parameters $low and $high in the following code. code :
function getRandomStrength($low, $high) {
// TODO: validate the input
$ln_low = log( $low, M_E );
$ln_high = log( $high, M_E );
$scale = $ln_high  $ln_low;
$rand = ( mt_rand() / mt_getrandmax() ) * $scale + $ln_low;
$value = round( pow( M_E, $rand), 1 );
return $value;
}

Random values with nonuniform distribution
By : Sandamal Perera
Date : March 29 2020, 07:55 AM

Generating random floatingpoint values based on random bit stream
By : user2740116
Date : March 29 2020, 07:55 AM
it should still fix some issue I don't think I'll ever be convinced that you actually need this, but it was fun to write. code :
#include <stdint.h>
#include <cmath>
#include <cstdio>
FILE* devurandom;
bool geometric(int x) {
// returns true with probability min(2^x, 1)
if (x <= 0) return true;
while (1) {
uint8_t r;
fread(&r, sizeof r, 1, devurandom);
if (x < 8) {
return (r & ((1 << x)  1)) == 0;
} else if (r != 0) {
return false;
}
x = 8;
}
}
double uniform(double a, double b) {
// requires IEEE doubles and 0.0 < a < b < inf and a normal
// implicitly computes a uniform random real y in [a, b)
// and returns the greatest double x such that x <= y
union {
double f;
uint64_t u;
} convert;
convert.f = a;
uint64_t a_bits = convert.u;
convert.f = b;
uint64_t b_bits = convert.u;
uint64_t mask = b_bits  a_bits;
mask = mask >> 1;
mask = mask >> 2;
mask = mask >> 4;
mask = mask >> 8;
mask = mask >> 16;
mask = mask >> 32;
int b_exp;
frexp(b, &b_exp);
while (1) {
// sample uniform x_bits in [a_bits, b_bits)
uint64_t x_bits;
fread(&x_bits, sizeof x_bits, 1, devurandom);
x_bits &= mask;
x_bits += a_bits;
if (x_bits >= b_bits) continue;
double x;
convert.u = x_bits;
x = convert.f;
// accept x with probability proportional to 2^x_exp
int x_exp;
frexp(x, &x_exp);
if (geometric(b_exp  x_exp)) return x;
}
}
int main() {
devurandom = fopen("/dev/urandom", "r");
for (int i = 0; i < 100000; ++i) {
printf("%.17g\n", uniform(1.0  1e15, 1.0 + 1e15));
}
}

random values with uneven distribution
By : Harsh Patel
Date : March 29 2020, 07:55 AM
it fixes the issue If you have your words in a list words, random.choice(words) will uniformly randomly select a word from the list. If you only have word lengths, I'd store the lengths and counts in a list: code :
len_counts = [
(1, 24), # 24 1length words
(2, 39), # 39 2length words
...
]

R  random distribution with predefined min, max, mean, and sd values
By : Faiz
Date : March 29 2020, 07:55 AM
I wish this helpful for you Discussion: Hi. It is very interesting problem. It needs quite an effort to be solved properly and not always solution can be found.

