Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

03-18-2015 , 08:22 PM
Maybe I'm not well versed enough in math for this, but I don't see what prime-ness has to do with this.

Doesn't writing rand4 based on rand9 suffer the same non-terminal fate? Over infinite trials, the probability of generating a number that doesn't need to be thrown out (< 9 in this case) approaches 1 but never reaches it right?

e.g 8/9 * 8/9 * 8/9 ...

Last edited by blackize5; 03-18-2015 at 08:27 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 08:36 PM
Its not specifically that they're prime, its that there's no way to get 5^n = 7^m the same way you can't get 4^n = 9^m. Whatever the precise way of stating that is. Has to do with prime factorizations. If I get any more specific I'll probably misstate something, but you know if there's a number in the prime factorization of the first value that doesn't appear in the prime factorization of the second, there's no way to make it work.

And here's a test case: Generate 1..12 from 1..18. Even though both prime factorizations are 2*2*3 versus 2*3*3, so it's all just 2's and 3's, you still can't get 12^n = 18^m because the ratios of 2's to 3's in the prime factorizations will always be different. I think it only works (guaranteed termination) if the larger number is evenly divisible by the smaller.

Last edited by JSLigon; 03-18-2015 at 08:45 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 08:49 PM
Quote:
Originally Posted by plexiq
Well, randomly choosing a number 1...5 requires log2(5)=2.3 bits of entropy. Your method uses an average of log2(7)*1.4=3.92 bits, which means it wastes about 41%.

To improve this, you can generate in batches of 6 rand5s, which would waste only around 8%.

Basically:
*) Use 5 rand7 calls to get a random number from 0...7^5-1
*) If the number is bigger 5^6-1, discard and repeat (only ~7% of the time)
*) Now you have a random number 0...5^6-1 that you can convert to 6 random base 5 digits
Ah... cool, thanks!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:03 PM
Quote:
Originally Posted by JSLigon
Its not specifically that they're prime, its that there's no way to get 5^n = 7^m the same way you can't get 4^n = 9^m. Whatever the precise way of stating that is. Has to do with prime factorizations. If I get any more specific I'll probably misstate something, but you know if there's a number in the prime factorization of the first value that doesn't appear in the prime factorization of the second, there's no way to make it work.

And here's a test case: Generate 1..12 from 1..18. Even though both prime factorizations are 2*2*3 versus 2*3*3, so it's all just 2's and 3's, you still can't get 12^n = 18^m because the ratios of 2's to 3's in the prime factorizations will always be different. I think it only works (guaranteed termination) if the larger number is evenly divisible by the smaller.
Yeah disregard that second paragraph, please, I'm completely wrong. Getting 1..12 from 1..18 with guaranteed termination is not difficult. Bolded part is correct.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:06 PM
Quote:
Originally Posted by Barrin6
I thought the same thing too at first, though you do have to agree this is inefficient.
I agree that it is initially offensive to the senses, especially from an academic/theory perspective. I It looks like it ends up being about as efficient as you can get without using some storage or something, but I didn't know that at the time and I wouldn't have been surprised to find some elegant mathy solution.

From a practical perspective, though, I wouldn't hesitate. The average running time is O(n) and it's easy to understand what's going on. Ship it!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:09 PM
Quote:
Originally Posted by Benholio
From a practical perspective, though, I wouldn't hesitate. The average running time is O(n) and it's easy to understand what's going on. Ship it!
Agreed.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:16 PM
Quote:
Originally Posted by JSLigon
Getting 1..12 from 1..18 with guaranteed termination is not difficult.
Do tell...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:32 PM
Ha, it might be kind of a fun puzzle so I'll put it in a spoiler. And I'm just going for guaranteed termination, nevermind efficiency.

Spoiler:

Assuming r18() returns a random int 1..18
Code:
x = r18();
if (x <= 12) return x;
y = r18();
if (y <= 12) return y;
if (x <= 15) return y - 12;
return y - 6;
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:43 PM
Quote:
Originally Posted by blackize5
Maybe I'm not well versed enough in math for this, but I don't see what prime-ness has to do with this.

Doesn't writing rand4 based on rand9 suffer the same non-terminal fate? Over infinite trials, the probability of generating a number that doesn't need to be thrown out (< 9 in this case) approaches 1 but never reaches it right?

e.g 8/9 * 8/9 * 8/9 ...
that's why i said co-prime. i think that's all you need.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:46 PM
Quote:
Originally Posted by JSLigon
Its not specifically that they're prime, its that there's no way to get 5^n = 7^m the same way you can't get 4^n = 9^m. Whatever the precise way of stating that is. Has to do with prime factorizations. If I get any more specific I'll probably misstate something, but you know if there's a number in the prime factorization of the first value that doesn't appear in the prime factorization of the second, there's no way to make it work.
Thank you for this explanation. It seems that all numbers in the prime factorization of the smaller number must be present in the prime factorization of the larger number, but doesn't that then simplify down to "For the problem write randX using randY to have a terminal solution, X must be a factor of Y?"

the example that lead me to that conclusion: rand4 from rand14 seems to be impossible despite all the prime factors of 4 being present in the prime factors of 14

Edit: Guaranteed terminating version of rand4 from rand14

Last edited by blackize5; 03-18-2015 at 10:00 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:54 PM


Class im supposed to design, the login screen

SPRITES! Jesus christ
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:55 PM
Quote:
Originally Posted by JSLigon
Ha, it might be kind of a fun puzzle so I'll put it in a spoiler. And I'm just going for guaranteed termination, nevermind efficiency.

Spoiler:

Assuming r18() returns a random int 1..18
Code:
x = r18();
# random distribution here
if (x <= 12) return x;
y = r18();
# random distribution here
if (y <= 12) return y;
# random distribution for 1..3 here
if (x <= 15) return y - 12;
# random distribute for 10..12 here
return y - 6;
See my comments in the spoil tags, it seems like now you bias to 1-3 and 10-12 and don't have equal probability for all numbers 1-12
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 09:56 PM
Quote:
Originally Posted by jmakin

Class im supposed to design, the login screen

SPRITES! Jesus christ
Holy ****. Sprites instead of asterisks. And then blinking sprites!? What is this, geocities?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:00 PM
My group leader is a moron
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:04 PM
Sorry meant implement not design, i obviously have no control over this future flaming pile of garbage
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:05 PM
Aren't you glad now that like 85% of your grade or whatever is based on having voluminous documentation that your professor will never read?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:14 PM
Quote:
Originally Posted by blackize5
See my comments in the spoil tags, it seems like now you bias to 1-3 and 10-12 and don't have equal probability for all numbers 1-12
Spoiler:

If the first call to r18() <= 12 or the second call to r18() <= 12, there's no problem right? So you're only concerned with what happens when x > 12 and y > 12. In that case, half the time x <= 15 and we return y - 12. The other half of the time we return y - 6. Since 13 <= y <= 18 (with equal distribution), this means half the time we return 1..6 and half the time we return 7..12. Still an equal distribution in 1..12.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:16 PM
Spoiler:
YES! Very clever! Sorry, I misread and thought both the 2nd and 3rd if statements were looking at the same variable.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:25 PM
Quote:
Originally Posted by blackize5
Aren't you glad now that like 85% of your grade or whatever is based on having voluminous documentation that your professor will never read?
No... He must have sensed my sour attitude, as soon as I came back from dinner break i got demoted to just producing documentation. Me and some other poor **** are responsible for all the state flow diagrams and ****.

So not only do i have no control over this project whatsoever ive been delegated to reading and interpreting everyone's ****ty code. Lol this might be the worst class ever.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:27 PM
Quote:
Originally Posted by jmakin
Sorry meant implement not design, i obviously have no control over this future flaming pile of garbage
When are you supposed to have your piece ready?

Edit: I posted while you were announcing your demotion. I think your demotion might be preferable to actually implementing the code but not sure.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 10:47 PM
Teacher gave an example program's documentation, it has all the features that I suggested that he dismissed as too difficult.

Yea it's difficult using your ****ty ass platform, ******
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 11:06 PM
Quote:
Originally Posted by gaming_mouse
that's why i said co-prime. i think that's all you need.
Not exactly. 6 and 4 are not co-prime but you can't get rand(6) out of rand(4) without the unbounded edge case. I think the following works: to get rand(n) out of rand(m) with a finite time guarantee, the set of prime factors of n has to be a subset of the set of prime factors of m.

Edit: apparently my pony's slow and this has already been pointed out lol.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 11:33 PM
Quote:
Originally Posted by suzzer99
Another two full days spent trying to figure out why our karma unit tests are failing in our rackspace environment but passing on our local. Sometimes they loop, sometimes they give indecipherable errors. Sometimes the order of the tests matters (so we've got some kind of weird side effects going on apparently). One time I was even able to get a group of 4 tests to fail by removing one of the tests.

Meanwhile other lead devs are starting to just comment out the unit test part of our build flow. And I'm completely swamped with actual development work. We have something like a dozen dev teams with maybe 70 devs and I'm the testing department. In my spare time

The funny thing is no one ever even officially assigned me to have anything to do with testing. I just did it because I wanted to learn and I was going to start looking for another job if I didn't get my promotion.

Well we do have 4 offshore dev testers who know how to write selenium tests but have no idea what they should be doing for our new stack. I'm also the branch manager/build engineer, along with two other guys - since our dev ops team is still just learning git/Jenkins/rackspace.

We've mostly given up on protractor end to end tests as they're impossibly unstable, as are our test users and test data.

Our CI/CD effort is an anatomy of a company talking about something but not really prepared to put any time, money or effort behind it. Bound to fail.

There has to be a huge market for a company which can come in as a consultant with a stable suite of unit and end to end testing tools. This stuff is the wild west for a monster site like ours. I feel like we encounter some new weird edge case every day. And the solution is usually just - let's try 100 things until something works - even though we have no idea why.
If you haven't watched these, you might find them helpful. Misko Hevery, the guy now known as the creator of AngularJS, was once beter known as an automated testing guru internally at Google and did a series of talks on how to write testable code, mainly aimed at Java developers but generally applicable regardless:

https://www.youtube.com/watch?v=wEhu57pih5w

https://www.youtube.com/watch?v=RlfLCWKxHJ0

https://www.youtube.com/watch?v=-FRm3VPhseI

https://www.youtube.com/watch?v=4F72VULWFvc

If nothing else, they should give you an idea of how hard it must be to get a strong automated testing initiative off the ground without a strong buy-in from everyone. Automated testing is something everyone talks about but something that I've rarely seen done properly. Getting everything set up mechanically so that tests can be written and run automatically is hard enough, but structuring everything so that different components are easy to isolate and test is harder and convincing everyone to do that properly is even harder. I find that even a lot of people who think they have it under control are often just going through the motion and writing tests to just to write tests, over-mocking habitually and testing implementation details as opposed to behavior.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-18-2015 , 11:41 PM
Quote:
Originally Posted by candybar
Not exactly. 6 and 4 are not co-prime but you can't get rand(6) out of rand(4) without the unbounded edge case. I think the following works: to get rand(n) out of rand(m) with a finite time guarantee, the set of prime factors of n has to be a subset of the set of prime factors of m.

Edit: apparently my pony's slow and this has already been pointed out lol.
that sounds right, ty.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-19-2015 , 12:15 AM
Quote:
Originally Posted by candybar
Not exactly. 6 and 4 are not co-prime but you can't get rand(6) out of rand(4) without the unbounded edge case. I think the following works: to get rand(n) out of rand(m) with a finite time guarantee, the set of prime factors of n has to be a subset of the set of prime factors of m.

Edit: apparently my pony's slow and this has already been pointed out lol.
This seems right except the part about it already having been pointed out. Where was that? This is how I tried to explain it to myself.

Ok so we have rand(m) and we want to generate rand(n) using k or fewer calls to rand(m) for some finite k. k calls to rand(m) will produce a sequence of return values and there are m^k such sequences, each equally probable. To get rand(n) as a uniform distribution we must partition those sequences into n equal sized groups, so m^k must be evenly divisible by n. Which is true if and only if the set of prime factors of n is a subset of the set of prime factors of m (as you stated).

The "or fewer" in "k or fewer calls" doesn't really matter. If some subsequences return early, we can consider that as mapping all possible full sequences that started with the subsequence to whatever value is returned.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m