How do I setup a formula to make ANY number into a number between X & Y ?

[Sloved]

Hello dear people,

I need some help out here because I'm a programmer and I want to make a script where the weather is predictable based on a given number (unix timestamp).

I am not bad at math but this goes a bit beyond my point of view,

what I want to do is to setup a formula to make any number into a number between chosen X & Y, for example:

Turn any number into a 'random but predictable' number between 20 an 30.

So for example if I want to turn number 1 using the 'formula' it would give the result 21

and if I do 2 it will go on till it reaches the max, then i I have the number 10 it begins again with 20 , or a random number between 20 and 30.

Can anyone help me out, please?

Thanks in advance.

Re: How do I setup a formula to make ANY number into a number between X & Y ?

Re: How do I setup a formula to make ANY number into a number between X & Y ?

there are different ways to do this. it depends on the kind of behavior you want your "numbers" to have.

for example, you could take N, and turn it into X + (N mod (Y-X)) (assuming X and Y, but not necessarily N, are integers).

if X = 20, Y = 30, this would take 352.67 to 20 + 2.67 = 22.67.

or, you could take N, and turn it into X + (Y-X)/2 + ((Y-X)/2)erf(N) (where erf(N) is the error fnction: Error function - Wikipedia, the free encyclopedia)

(this will have the effect of making large -N close to X, and large N close to Y).

or, you could take N, and turn it into X + (Y-X)(e^(-N^2))

(this will make large and negative values for N close to X, and values close to 0 close to Y).

there are a LOT of ways to do what you describe, but they will perhaps not all produce the behavior you are looking for.

Re: How do I setup a formula to make ANY number into a number between X & Y ?

That sounds to me like a great way to deal with my problem, thank you :)

But yes this is a simple manner, now I have an additional optional question:

How can I make some 'ranges' for that? ex N >= 50 and N < 100 will make the result 1 and N >= 100 and N < 150 will make result 2 or something, Can this be done 'easily'?

it would be a bit silli in the game if the weather did change each second haha.