My Math Forum  

Go Back   My Math Forum > Science Forums > Computer Science

Computer Science Computer Science Forum


Reply
 
LinkBack Thread Tools Display Modes
October 14th, 2011, 01: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 (1-1000, 1001-2000, 2001-3000... 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!
xcure is offline  
 
October 14th, 2011, 02:07 AM   #2
Senior Member
 
MarkFL's Avatar
 
Joined: Jul 2010
From: St. Augustine, FL., U.S.A.'s oldest city

Posts: 12,211
Thanks: 520

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
MarkFL is offline  
October 14th, 2011, 03: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!
xcure is offline  
October 14th, 2011, 03:12 AM   #4
Senior Member
 
MarkFL's Avatar
 
Joined: Jul 2010
From: St. Augustine, FL., U.S.A.'s oldest city

Posts: 12,211
Thanks: 520

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.
MarkFL is offline  
October 14th, 2011, 05:51 AM   #5
Newbie
 
Joined: Oct 2011

Posts: 3
Thanks: 0

Re: Fit number to a range

Thanks! That works perfect!
xcure is offline  
Reply

  My Math Forum > Science Forums > Computer Science

Tags
fit, number, range



Search tags for this page
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 06:16 AM
Number theory and finding the domain and range! chocolate Algebra 2 April 12th, 2012 09:41 PM
range of f(x) panky Calculus 0 March 20th, 2012 06:30 AM
Range of f(x) panky Calculus 3 January 20th, 2012 05:57 AM
Convert binary range with fixed number of zeros/ones hans-de-jong Number Theory 2 June 30th, 2009 05:15 PM





Copyright © 2019 My Math Forum. All rights reserved.