October 14th, 2011, 12:55 AM  #1 
Newbie Joined: Oct 2011 Posts: 3 Thanks: 0  Fit number to a range
Hello First, I don't know if im posting in the right forum... So please move the post if its not in the right place. Im very week in math So here is the problem im facing: I have conceptual ranges with even difference of 1000 (11000, 10012000, 20013000... and so on to infinity). Now, lets say there is an algorithm that randomly generates numbers. When number generated I want to know to what range it belongs, for example: if random generated number is: 11155 I want to know that its fit to range where lower limit is 11001 and higher limit is 12000 Thanks in advanced! 
October 14th, 2011, 01:07 AM  #2 
Senior Member Joined: Jul 2010 From: St. Augustine, FL., U.S.A.'s oldest city Posts: 12,211 Thanks: 521 Math Focus: Calculus/ODEs  Re: Fit number to a range
One way might be to use the floor function. Let n denote the random natural number. Let Then put the random natural number n in its range with: If R = n then to else to end if 
October 14th, 2011, 02:08 AM  #3 
Newbie Joined: Oct 2011 Posts: 3 Thanks: 0  Re: Fit number to a range
Thanks for a quick reply! I do not understand this expression: Can you write it as code (c#, c++) or something please? As i said, very week with math Thanks! 
October 14th, 2011, 02:12 AM  #4 
Senior Member Joined: Jul 2010 From: St. Augustine, FL., U.S.A.'s oldest city Posts: 12,211 Thanks: 521 Math Focus: Calculus/ODEs  Re: Fit number to a range
It's been quite a while since I coded in C, but there may be a floor(x) function in your math library. If so, write: R = 1000*floor(n/1000) edit: any function that truncates the digits to the right of the decimal point will work. Maybe there's an int(x) function (returns the value of the real number x as an integer whose magnitude (or absolute value: abs(x)) is rounded down to the greatest integer (returned by int(x)) less than or equal to abs(x), then this int(x) has the original sign of x restored. Now, I'm sure the library function does it much more efficiently, that is essentially what needs to be returned by the definition of the int(x) function. I would look at your compiler docs to find specific information about the int(x) and floor(x) functions. Just find one that essentially cuts off, or truncates to the right of the decimal point of a real number representation. 
October 14th, 2011, 04:51 AM  #5 
Newbie Joined: Oct 2011 Posts: 3 Thanks: 0  Re: Fit number to a range
Thanks! That works perfect!


Tags 
fit, number, range 
Search tags for this page 
write the number that fits in the range,scale a range of number to fit another range,write the numbers that fit in the range
Click on a term to search for related topics.

Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Calculating a position in a range while limiting the range  tale  Computer Science  5  May 23rd, 2012 05:16 AM 
Number theory and finding the domain and range!  chocolate  Algebra  2  April 12th, 2012 08:41 PM 
range of f(x)  panky  Calculus  0  March 20th, 2012 05:30 AM 
Range of f(x)  panky  Calculus  3  January 20th, 2012 04:57 AM 
Convert binary range with fixed number of zeros/ones  hansdejong  Number Theory  2  June 30th, 2009 04:15 PM 