# Reviewing the road generation system generation of normal…

• generation of normal and tangent for each segment (cyan & purple vectors): they can be used easily to generate a new road starting from any point;
• a million better random selection, based on the formula: X1 = a*X0 + b % m;

This random generation merits a bit of attention.

Until now, i was randomly picking a new start point from an existing road to create a new road. The process is consuming, and there is no guarantee to avoid picking several time the same point on the same road.

With the formula above, found in the great numberphile channel (see below), I attribute once and for all a random to each road’s dot. The particularity of this random generation is that it will NEVER repeat two times the same value in one sequence. Once generated, my dots have a number in the range [0,1], with a linear distribution.

For instance, in a line having 10 dots (and therefore 9 segments), each dot will have a random number between 0 and 1. If you order the list of dots by random values, and compare the gap between each sorted values, the average gap will be 0.1!

The way to use this random number is straight forward. If you want to generate a secondary road on 50% of the dot of the first one, you just have to loop over these number and check wherever the random value of the dot is < 0.5. If the distribution was not linear, doing this would not guarantee to create on sub-road every two dots. As it is, you can just specify the percentage, all random calculation has already been done, and in a more controlled way then ofRandomuf() does it.

This formula requires big prime numbers (>10000) to be placed at a and b. Here is the source i used: list of primes.

This site uses Akismet to reduce spam. Learn how your comment data is processed.