Results 1 to 4 of 4

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

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    2

    Cool 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.
    Last edited by grasmanek94; June 23rd 2011 at 02:30 AM. Reason: Sloved
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member

    Joined
    May 2006
    From
    Lexington, MA (USA)
    Posts
    11,749
    Thanks
    648

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

    Hello, grasmanek94!

    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 1.
    And if I do 2, it will give 2, and so on till it reaches the max.
    When I have the number 10, it begins again with 20, and so on.

    Can anyone help me out, please?

    I'll assume that we are dealing with integers (whole numbers).


    Given a number N:

    . . (1) Divide by 10 * and note the remainder.

    . . (2) Add 20 to the remainder.


    \text{Example: }73
    . . 73 \div 10 \:=\:7\text{, rem. }3
    . . \text{Then: }3 + 20 \:=\:23

    \text{Example: }198
    . . 198 \div 10 \:=\:19\text{, rem. }8
    . . \text{Then: }8 + 20 \:=\:28

    \text{Example: }850
    . . 850 \div 10 \:=\:85\text{, rem. }0
    . . \text{Then: }0 + 20 \:=\:20


    * \text{The "10" is the difference }30\!-\!20.

    Follow Math Help Forum on Facebook and Google+

  3. #3
    MHF Contributor

    Joined
    Mar 2011
    From
    Tejas
    Posts
    3,397
    Thanks
    760

    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.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Newbie
    Joined
    Feb 2010
    Posts
    2

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

    Quote Originally Posted by Soroban View Post
    Hello, grasmanek94!


    I'll assume that we are dealing with integers (whole numbers).


    Given a number N:

    . . (1) Divide by 10 * and note the remainder.

    . . (2) Add 20 to the remainder.


    \text{Example: }73
    . . 73 \div 10 \:=\:7\text{, rem. }3
    . . \text{Then: }3 + 20 \:=\:23

    \text{Example: }198
    . . 198 \div 10 \:=\:19\text{, rem. }8
    . . \text{Then: }8 + 20 \:=\:28

    \text{Example: }850
    . . 850 \div 10 \:=\:85\text{, rem. }0
    . . \text{Then: }0 + 20 \:=\:20


    * \text{The "10" is the difference }30\!-\!20.
    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.
    Last edited by grasmanek94; June 23rd 2011 at 02:45 AM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 5
    Last Post: November 19th 2011, 09:10 PM
  2. Replies: 4
    Last Post: March 8th 2011, 07:18 AM
  3. a formula for the number of edges
    Posted in the Differential Geometry Forum
    Replies: 0
    Last Post: October 31st 2009, 12:58 PM
  4. number of ways to make team
    Posted in the Statistics Forum
    Replies: 3
    Last Post: December 4th 2008, 03:23 AM
  5. make number
    Posted in the Algebra Forum
    Replies: 3
    Last Post: August 15th 2008, 05:31 PM

Search Tags


/mathhelpforum @mathhelpforum