Jump to content

corbin

Staff Alumni
  • Posts

    8,102
  • Joined

  • Last visited

Everything posted by corbin

  1. I guess you could consider me quite unnationalistic. I mean I think the US is a great place and all, but I don't think it's the best country or anything. I guess even having to think about if I'm patriotic or not probably signifies no (lol).
  2. corbin

    Religion

    At least he didn't say some "God does everything for a reason!" crap. I hate that answer to questions. But seriously, I think 99.99999% of people would've been quite flustered.
  3. The thing you have to remember about PHP and UTF-8 is that PHP pretty much sucks at handling multibyte charsets. (Which is really no fault of its own to some extent.) Are you altering the text at all or just straight up echoing it? If you're altering it first, you will need to make sure to use multibyte or binary safe functions. If not, then I'll think type out other stuff.
  4. RewriteRule ^(.*)$ /foo/bar/index.php?page=$1 /foo/bar.... technically matches ^(.*)$ The easiest way to work around that is to just check if the file exists: RewriteCond %{SCRIPT_FILENAME} !-f RewritRule ...
  5. If you're trying to do what I think, this should work: SELECT type, COUNT(type) as cc FROM t1 GROUP BY type ORDER BY t1 DESC LIMIT 1;
  6. corbin

    Religion

    Just of curiosity, do you envision the Christian idea of god, or just the presence of a deity?
  7. Hrmmm.... Yeah, guess it's one of those things that just doesn't make sense to me at the moment. (I plan on reading more later .) As for factorials, I figured it was something like that, but don't remember what. I remember a couple years (probably like 5 lol) back when we first did factorials we had to write them out the longway for like a week just so we would see that x.x. (Apparently I didn't remember though hehe.)
  8. $apps_html.= '<td><a href="window.html" onclick="popUp(this.href,'200','400'); Should be: $apps_html.= '<td><a href="window.html" onclick="popUp(this.href,\'200\',\'400\');'; When ever you use ' inside of ' you have to put \' if that makes sense.
  9. Yeah, I've been thinking about it for like 15 minutes now, and I just had a breakthrough. I thought about it backwards like Daniel suggested and realized that the first term has a x/x probability, then the second a x-1/x, then x-2/x and so on.... Thus the probability of having unique terms: 1-(rangeSize-0)(rangeSize-1)(rangeSize-2)....(rangeSize-setSize). I kept wondering why Daniel's equation had to use factorials, then once I thought about it backwards it made sense. (I would assume Daniel's and my equation are the same [especially considering I stared at his for 10 minutes and that's what made me realize that haha] although I don't know how to prove that.) I still don't fully understand why doing it forwards instead of backwards does not work the way I thought it did, but I do get the backwards way now. Well, I do understand why since what you said with the two way pair thing would make mathematical sense, but I guess I don't understand why that's the way it is. I guess I'm trying to look at it as statistically independent pairs or something. Or maybe I'm just thinking of it how I would do it in my head. I would go through and compare x to every term in Y which would only be |Y| possibilities, but, as you two have both pointed out, that wouldn't make sense math wise.
  10. corbin

    Religion

    Not as long as people only state their own beliefs and don't question each other's . Anyway, I grew up Christian and still go to church every now and then (although usually just to appease my parents), but I would consider my self either atheist or probably more accurately agnostic. I'm not sure that there is a god, but I'm not sure that there isn't either is what it basically comes down to. It's also my feelings that if a god doesn't feel the need to display his existence to me, I don't see the need to blindly have faith. (That's never made sense to me. Why would God [as in the Christian god since that's what I'm most familiar with] essentially make us have faith? If he wants us to worship him, why not show us that he exists? I've gotten free will answers before, but that doesn't really make sense. I think that to truly believe in Christianity is to not believe in free will. Well, perhaps free will isn't the right term, since you can do what ever you want just not without consequences.) Edit: Typed this while zanus was posting apparently. (Just stating, not saying if anything conflicts or agrees or anything.)
  11. I get a little line break crazy sometimes. For some reason I mentally separate chunks of text in little blocks. I'm not sure if I misspoke or if my math was wrong. I meant to have the probability of having a duplicate on the term n and only on the term n, not in the process of going from 1 to n. My logic behind checking that was that if there are 50 terms in the result set, 100 terms in the possible set and the 51st term is being chosen, 50 terms are taken, thus 50 are open, meaning a 50/100 chance or 50%. Based on "How many elements do you need to pick before you have a 50% chance of picking the same number again?" we were talking about different things. I guess it was confusion how I lacked structure in my post and kind of rambled back in forth between selecting a term and the process of getting to a term. Or is my math still wrong? I just realized that based on your math, my equation involving the summation must've been wrong. (Well, it was definitely notated incorrectly since I had x->n and should have said something like x = 0 until x = n.) I don't think you're wrong since I suck at probability, but I don't see the error in my math. 10th element in 100 possible: sum (n-1)/100 x = 0 until x = n So, the probabilities: 0/100, 1/100, 2/100....9/100. Once again, the first time, 0 terms are taken hence 0/100 chance. The second time 1 term is taken, hence a 1/100 chance. The 10th term 9 terms are taken hence a 9/100 chance. Basically I don't see why assuming r(a, b) is a function that returns a random number c such that a <= c <= b with the number d such that a <= d <= b would not have the probability of being selected of 1/(b-a+1). Is that where my logic is going astray, or is it in thinking that that concept continues for subsequent numbers?
  12. Yeah an algorithm would definitely be the best solution. I really just don't see the issue with a random number generation scheme. A 12 digit number! I would go with a different approach if he were generating like 1 million numbers and only had a 8 digit limit or something, but 500 million is nothing out of hat of 12 digits. Hmmm, I guess a behind the scenes generation could be good though, although I do see a problem. In the long run it would be better if he ever did approach even like 25% of the maximum options. The problem though is that the chances of having locking problems is much higher. If you have 1,000 numbers generated, a script is limited to those random numbers. Otherwise, yeah, a script may have collisions generating random numbers, but what are the chances it will have a collision with a script running simultaneously?
  13. Pros of PHP (in my eyes): -Free (Perl/Python/JSP are also free, and ASP/ASP.NET sort of are....) -Cross platform (as are Perl/Python/JSP and ASP/ASP.NET to some extent) -It's the language I know best Limitations? Any limitation in PHP could be overcame if the functionality were added to the PHP code. As for that happening, yes, there are certain things that PHP will never be able to do. Example: One of my pet peeves about PHP and what makes me use Java or C++ sometimes is the lack of threading. In a web environment threading is pretty useless 99% of the time though when it comes to the end language. I doubt threading will ever be added to PHP.
  14. You would have to fetch the content based on the name. Like, you would have to pass the name to the URL and then check the DB based on the name.
  15. Pretty basic errors really. All quite self explanatory. "[Mon Oct 05 14:17:07 2009] [notice] cannot use a full URL in a 401 ErrorDocument directive --- ignoring!" Errr.... You can't use a full URL in a 401 ErrorDoc directive. Actually, your ErrorDocument statement for 401 is not using a full URL. Do you have any htaccess files anywhere using a full URL? [Mon Oct 05 14:17:07 2009] [warn] RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored. Looks like it's also in a htaccess file. Basically it means that: RewriteCond <something> -f [NC] is not valid. Since file paths are case sensitive, there could be numerous ways that Apache could handle that. [Mon Oct 05 14:22:16 2009] [error] [client 220.181.94.235] File does not exist: /usr/local/apache/htdocs/bbs Users keep requesting /bbs/ which doesn't exist. Why they're requesting it, I have no idea. Perhaps you have a broken link somewhere. Can't use string ("2.3") as a HASH ref while "strict refs" in use at /usr/local/apache/htdocs/404.cgi line 162. No idea what that means. Would need to see 404.cgi.
  16. Well, that's with a set of numbers that's relatively large in comparison to the set it comes from. For example, the chances of having a duplicate when generating 10 random numbers out of 100 possible is about 50%. 5 numbers out of 100 is only 10% oddly enough. 25 numbers is 300% (so you would theoretically have 3 dupes). Think about this: For simplicity, assume that valid numbers are 00-99. That's 100 possibilities. Now, let's assume you generate a set of random numbers from that range: {a, b, c, d, ...} Now, what is the probability of a repeat the first time? 0/100. Second? 1/100. Third? 2/100. Basically, the chance of a repeat is: p(n, m) = (n-1)/m Where n is the number of the term being generated and m is the max number of options. (For the 3rd number, n = 3 for example.) So, to find out how many collisions you would have when doing an entire set: What are the chances of having a collision with 5 numbers out of 100? Well, it's 0/100 + 1/100 + 2/100 + 3/100 + 4/100 A 10% chance that you'll have a collision (which isn't very surprising). So, the probability of having a collision by generating the Nth term is: p(n, m) = sum (x-1)/m as x -> n So, going back to earlier, to find the number of terms you must have to have a certain chance of a collision, it would go like this: chance of collision = (n-1)/m m(chance of collision) = n - 1 n = m(chance of collision) + 1 So, if you had 0-99 and wanted to know how many numbers you would have to have before a 50% chance: n = 100(50%) + 1 n = 50 + 1 n = 51 So, to extend that to the actual numbers... To even have a 10% chance of collision with 100000000000-999999999999: n = (9*10^11)(10%) + 1 = (9*10^10) + 1 = 90000000001 You would have to have 90000000001 terms before having even a 10% chance of making a collision! But really what it all comes down to is how much time is wasted when a collision does happen. My GenerateCode() function from earlier on my quite crappy computer averages about 543.866 nano seconds per run. So figuring out how much time is wasted generating 500 mil item ids: 138889 clashes (well, that's based on probability so it would of course fluctuate, potentially highly sometimes). 138889 * 544 * 1/10^9 = 0.075555616 seconds. That does not factor in database calls and what not of course though. Also, it assumes a perfectly random generator. In reality, the random number generating in computers is far from perfectly random in most cases. I feel like my math is wrong (if it is, I'm sure someone will math pwn me ), so I shall now test it. I expect about 200k duplicates in 500000000 loops. .
  17. Now is a static variable (technically it would be called a member since it's a variable in a struct*) in the structure DateTime of the type (type). *Assuming you want to use the same terminology when talking about structs that you would use when talking about classes "How can i assign the member of the structure to the structure variable ??" Technically you cannot do this: struct Struct1 { Struct1 var; } But oddly enough the reason is not because of the recursiveness (technically all variables are really just pointers to memory, so it doesn't matter where it points or if it even points anywhere). The reason you can't do it is because the compiler doesn't yet know what Struct1 is while inside of Struct1. If my theory is correct, then technically it would be doable with a class since you can use prototypes with classes (well in C++ you can; don't know about C#).
  18. He said they have 500 million records... 10^12 is 1000000000000... 1000000000000-500000000 = 999500000000 free codes. Actually, I just realized that my math is wrong since the number can't start with 0. It's actually: 9*10^11: 900000000000 So 900000000000 - 500000000 = 899500000000 codes. Anyway, if they need to generate 499 million more codes, there's obviously room in the set for that, but it comes down to a question of how many wasted generations there will be. I don't actually feel like thinking about the math on that, but assuming a decent randomness algorithm, it would be quite rare. Anyway, I could ramble all day, but that doesn't really accomplish anything. <?php ini_set('memory_limit', '1G'); $iters = 10000000; //1 million iterations $codes = array(); $clashes = 0; $START = microtime(true); for($i = 0; $i < $iters; ++$i) { $c = (string) GenerateCode(); //If it's not casted to a string, then PHP might mess with it when setting it as the array key. //(It appears that PHP casts numbers to ints when using them as an array key....) //The reason it's as the array key instead of the value is for speed. //It's faster to search an array by a key than to call in_array over and over again //because of the way hash maps work. if(!isset($codes[$c])) { $codes[$c] = true; } else { ++$clashes; } } $END = microtime(true); echo "There were $clashes clashes out of $iters codes generated.\n"; echo "It took " . ($END - $START) . " seconds.\n"; function GenerateCode() { //just for kicks let's break it into 4 3 digit chunks $c1 = mt_rand(100, 999) * pow(10, 9); $c2 = mt_rand(0, 999) * pow(10, 6); $c3 = mt_rand(0, 999) * pow(10, 3); $c4 = mt_rand(0, 999); return $c1 + $c2 + $c3 + $c4; } There's typically 0-1 clashes per 1,000,000 codes generated. I ran it with 10m iterations a couple times in hopes of getting a more accurate number of clashes, and it seemed to be about 55 clashes.
  19. Errrr.... No offence intended, but that's not exactly the best way to go about it. 12 digits: 10^12 possibilities. 1000000000000 options at 4 bytes each: 37.35GB. Anyway, the reason why you're only getting 162 unique numbers in that many iterations is because computers cannot technically come up with random numbers. (Which makes sense if you think about what a computer does....) Random numbers in computers must be based off of time. Typically the time is run through an algorithm to come up with a number. (Technically any seed can be used, but for any seed x, the same set of random numbers will always be generated.) Mathematically: If r(x) generates a set sized y, if r(x) is run more than y times before x changes, the set will begin to repeat. So, one option would be to seed your self: Something like this could work: do { $random = mt_rand(); //mt_rand is much more random than rand() since it's based off of more than seconds //you would need to use something besides just mt_rand() to generate a code, but you get the point. $codeExists = mysql_query("SELECT 1 FROM items WHERE code = {$random};"); } while(mysql_num_rows($codeExists)); As for the query, you will want to make sure you have an index on what ever column you're checking.
  20. By the way, renaming a file is essentially the same as moving it.
  21. I think the PCRE functions are all quite ninja. But really nothing ever surprises me. I think it's because I started on PHP, so I expect all the super simplifying functions to be there lol.
  22. Well, that depends what you're storing in the columns. What makes you think it's the database? Have you turned the slow query log on?
  23. I would suggest looking into a POST tutorial, and looking at the mail function.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.