I need to generate random numbers for several charts that go up and to the right.
I'm using a JavaScript charting engine so will ultimately require numbers in JSON, but I can handle the conversion if you have an easy way outside of JavaScript.
Here's a simple randomNumber generator in JavaScript:
function randomNumber(minimum, maximum){
return Math.round( Math.random() * (maximum - minimum) + minimum);
}
console.log(randomNumber(0,100));
The above would work if min
and max
grew over time. Can you point me in the right direction?
Here's a JSFiddle to try out various solutions, including a handy chart: http://jsfiddle.net/9ox4wjrf/
Here's a rough example of the sorts of charts I need to build with generated data:
Something like this may work:
var a = 0.05;
var b = 10; //play with these values to your liking
var y;
//loop here from 0 to whatever
y = a * x^2 + b * x * Math.random();
//or using your randomMumber function:
y = a * x^2 + randomMumber(- b * x / 2, b * x / 2);
This way the noise gets bigger when further to the right
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With