-
Nov 9th, 2014, 04:22 AM
#1
Thread Starter
Lively Member
Logarithmic question
I've got a random number between 0 and 1 (simple Rnd() function). If the number is less than 0.1, I need to know how many times you'd need to multiply 0.1 by 0.9 to get under the value I have. I also need to know the reverse. That is, the same number of multiples of some number (which I can't even guess at) will get you closer to 1 without going over.
I'm sure it's going to be based on math.log10 function, but I don't know how...
Last edited by OddGamer; Nov 9th, 2014 at 05:00 AM.
-
Nov 9th, 2014, 05:03 AM
#2
Re: Logarithmic question
Say x is the random number. If x < 0.1, you want to know when 0.1*0.9^y = x (essentially); this occurs for y = log_(0.9) (x/0.1) = (1+log10(x))/log10(0.9). For instance, if x = 0.0324, this gives 10.696.... Note that 0.1*0.9^10 = 0.03486... while 0.1*0.9^11 = 0.03138.... Take the ceiling of the value to get the first integer for which 0.1*0.9^n <= x.
For the reverse, if x > 0.9, you likewise want to know when 0.9*1.1^y = x, which occurs for y = log_(1.1) (x/0.9) = (1+log10(x/9))/log10(1.1).
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Nov 9th, 2014, 05:42 AM
#3
Thread Starter
Lively Member
Re: Logarithmic question
Sure! Answer before I can be more specific! :P I shouldn't post these while distracted.
You have the first part right, but I badly specified the other half. My bad again.
f(A). If A = .01 you get N. If A = .99 you also get N.
If A = .01, N = 22. This is the number of times you'd have to multiply .1 by .9 to get A. That is, .1*(.9^N) = A when A < 0.1.
With the inverse I'm not sure what the multiple would be, honestly.
Maybe take your equation for the first part, but apply it to 1-A when A > .9? Would that do it?
Last edited by OddGamer; Nov 9th, 2014 at 05:47 AM.
-
Nov 9th, 2014, 03:21 PM
#4
Re: Logarithmic question
I can't really understand your revised version, sorry. What I know so far: if A (the random number) is > 0.9, compute N = ceil((1+log10(1-A))/log10(0.9)), which is the smallest N such that 0.1*0.9^N <= 1-A. You then want to know which number B satisfies... something. Maybe 0.9*B^N = A? If so it's just an Nth root away. Perhaps you'd be able to write your condition as an equation, which would be clear.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|