Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Gradient Weighted random number

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
3 replies to this topic

#1 treeway   Members   

108
Like
0Likes
Like

Posted 05 October 2011 - 03:31 AM

Hi

I have two points (A,B) and I want to create a set of random points between the two, such that most points are close to A and the number of points decreases linearly towards B. Does anyone know a simple way to solve this?

Thanks

#2 Rene Z   Members   

605
Like
1Likes
Like

Posted 05 October 2011 - 07:33 AM

Random number generators generating values between zero and one with an uniform distribution are common. You can take the squared output of such a generator, and then use to to scale the vector (B-A) and add it to A.

In pseudocode:
uniformRand = rand();

outputPoint = A + uniformRand*uniformRand * (B-A);


#3 Bregma   Members   

9093
Like
1Likes
Like

Posted 05 October 2011 - 08:32 AM

I have two points (A,B) and I want to create a set of random points between the two, such that most points are close to A and the number of points decreases linearly towards B. Does anyone know a simple way to solve this?

It sounds like you need to generate random numbers on a geometric or exponential distribution. If you're using C++ and your development environment supports the current ISO standard, you can just use std::geometric_distribution or std::exponential_distribution from <random>. If you're not in that situation, you can try to write them yourself, it's not that difficult.
Stephen M. Webb
Professional Free Software Developer

#4 treeway   Members   

108
Like
0Likes
Like

Posted 05 October 2011 - 08:51 AM

Thanks for the reply guys Rene Z's response worked perfectly for my situation (I'm not using C++), but I will look into std::geometric_distribution and std::exponential_distribution just out of interest, so thanks for that Bregma.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.