// This makes it less likely that `value` will be 10
// the more times you multiply, the less likely you will be to reach
// the maximum potential value
const value =Math.random()*Math.random()*Math.random()*10;
I use this a fair amount when creating artwork with code. I’ll usually use a seeded random though for more control.
I was thinking about different icons I might use in a node based programming environment to denote this use of random and after a little futzing around created this series of histograms:
function rand(n =1, f =1){
let value =1;
for(let i =0; i < n; i++){
value *=Math.random();
}
// fixing the value so that it fits
// nicely as a key in the hash table
// hash = {
// 0.2: 5,
// 0.9: 8,
// etc...
// }
return value.toFixed(f);
}
function histo(n =1, f =2, off, iter =1500, size =70){
const vals ={};
const canvas = document.createElement('canvas');
const c = canvas.getContext('2d');
canvas.width= canvas.height= size;
canvas.style.margin='.5em';
document.body.appendChild(canvas);
for(let i =0; i < iter; i++){
const randNum = off ? off - rand(n, f): rand(n, f);
Was looking through some old code and saw something like this… people don’t like with and it doesn’t work in “strict mode”… I use it here on Snippet Zone for fun speed-coding stuff…