Pacha
Pacha

Reputation: 1526

Shrink range of numbers

Lets say I have a random number, that goes from 0.0 to 1.0, and I want to reduce its "range", to, lets say 0.25 to 0.75 respecting its harmony.

What would be the pseudo code for this?

Examples:

0.0 in the [0.0, 1.0] range would be 0.25 in the [0.25, 0.75] range

0.5 would still be 0.5

Thanks.

Upvotes: 2

Views: 1072

Answers (1)

Juri Robl
Juri Robl

Reputation: 5746

You have a random number r. First you shrink the range: r = r * (0.75-0.25). Now it's in the range [0, 0.5]. Then you shift the range: r = r + 0.25. Now it's in the range [0.25, 0.75].

Upvotes: 5

Related Questions