Simple algorithm for generating random numbers with bigger smaller probability

0 votes
I'm currently working on a game, with scrollable screen and I need to find a simple algorithm for placing obstacles in the game. I have a gameSpeed, that is increased in time (from 1 to 12, increased by 0.005 each 1/60s) and a range of available positions between 200 and 600 (ints). I'd like to achieve a bigger probability of receiving smaller number when the speed is bigger, but it's my 14th hour straight coding and I cannot come up with anything usable and not overcomplicated. I'd like to minimize Math and random functions so that the rendering loop won't take too long. Any help appreciated !
Mar 26 in Machine Learning by Dev
• 6,000 points
33 views

1 answer to this question.

0 votes

To move the density in one way, you may square or square-root the random number. Math.random()*Math.random() will produce smaller integers (around 0) with a higher chance than larger ones (near 1).
Your formula could be something like this:

var position = Math.pow(Math.random(), gameSpeed / 3) * 400 + 200;

Or
Make an array with more lower values than higher ones, for example, to generate random integers between [1,5]. (both inclusive). As an example, your array could be [1,1,1,1,1,2,2,2,3,3,3,4,4,5].

And if you pick an element from that array at random, you'll have a better probability of picking a low number than a high one.

answered Apr 4 by Nandini
• 5,480 points

Related Questions In Machine Learning

0 votes
0 answers

Create random numbers with left skewed probability distribution

I would like to pick a number ...READ MORE

Mar 25 in Machine Learning by Dev
• 6,000 points
61 views
0 votes
1 answer

Getting one word as caption with zero probability using pretrained checkpoints for image captioning-im2txt

Under caption_generator.py change the following line as follow ...READ MORE

answered Feb 27 in Machine Learning by CoolCoder
• 4,360 points
32 views
0 votes
1 answer
0 votes
1 answer

How to simulate first passage time probability in python for a random walk?

To begin with, you're now computing fp ...READ MORE

answered Apr 5 in Machine Learning by Dev
• 6,000 points
145 views
0 votes
1 answer

Crypto algorithm list

The learning here is that cyphers and ...READ MORE

answered Apr 7 in Blockchain by Aditya
• 7,280 points
61 views
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
212 views
0 votes
1 answer

Migrating proxy npm repo in nexus 3

I don't think you can achieve this ...READ MORE

answered Jun 22, 2018 in DevOps Tools by DareDev
• 6,890 points
795 views
+1 vote
1 answer

What is the difference between JavaScript and Java

This quote rightly explains that 2 totally ...READ MORE

answered Jun 29, 2018 in Java by Daisy
• 8,120 points
244 views
0 votes
1 answer

Random numbers with user-defined continuous probability distribution

You can use the rejection sampling approach ...READ MORE

answered Mar 25 in Machine Learning by Nandini
• 5,480 points
31 views
0 votes
1 answer

Plotting joint probability of two random variable choices

Create pandas.DataFrame , you can use seaborn.jointplot ...READ MORE

answered Mar 23 in Machine Learning by Nandini
• 5,480 points
62 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP