hcdarkmage Posted August 21, 2007 Share Posted August 21, 2007 Has this happened to you? You wake up one morning feeling that nothing can go wrong . . . and then you get to work (or school). You have worked long and hard on a function in PHP that shuffles elements and plugs them into slots that were requested. You spent hours, days, weeks, maybe even months on this program and it works as it is supposed to (thanks to your online friends at phpfreaks). You upload it and everything is great and (almost) everyone is happy. Then it strikes. The hosting service decides to drop you without warning. Your website loses traffic for 3 days because they don't want to talk to your company's web rep. So the main man decides to pull it internal. Now here is what gets me. The program works like a charm, even after being put on an internal server, but the "boss" decides that "it isn't random enough". How could something not be random enough? It isn't like I went through and created the algorithm that tells it how to shuffle. I just used the standard command and it worked fine for him until we moved it internally. I get my *** handed to me for the things I cannot control. Me, being the friendly person that I am, decide to tell him I will try and work on it. How would you handle this situation? Quote Link to comment Share on other sites More sharing options...
zq29 Posted August 22, 2007 Share Posted August 22, 2007 Ask him what he means by "not random enough", ask him to give you examples of how it currently works, and them ask him for examples of how he wants it to work. His answers might give you the opportunity to point something out, or at least come back here and ask how easy it is to do what he's asking... Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 22, 2007 Author Share Posted August 22, 2007 He said that there are a lot of repeats when he clicks on the button or refreshes. Well . . . what do you expect when you are filling 5 slots with 9 names and 3 slots with 6 names. There is bound to be repeats and they are bound to go into the same slot they were in before you hit the refresh button every now and then. I have never seen a problem with it when I go through and hit the refresh button. I think what it is is that the random "people" who come up, some do come up more often then others. When "competing people" look on the site and hit the refresh, they feel they are being cheated out of time in the list. So the "boss" chews me out for it. If you set up a program that takes the numbers 1-9 and tell it to display 5 numbers randomly, there will be times when you get 2, 7, 4, 8 and 1 in that order. Some times 7 and 4 will show up, in that order, twice in a row. That is how it happens. I don't know. Maybe he just wants to get the "people" out of his hair about not showing up as often as others do. Oh well. Quote Link to comment Share on other sites More sharing options...
zq29 Posted August 22, 2007 Share Posted August 22, 2007 I think there is actually some truth in what your boss has pointed out, I've often wondered how random the rand() function actually is. <?php $nums = range(1,6); for($i=0; $i<3; $i++) echo $nums[rand(0,count($nums)-1)]; ?> Refreshing this script 10 or so times, I got results such as '444', or '111' several times, surely something is up if it is picking the same random number consecutively 3 times, on several occasions. Bare in mind, that I am working with a range of ,1-6, change that to 1-600 and the results are a lot more random. I guess with small ranges, the probability is high that you're going to get results such as '444' and '111' on multiple attempts. I'm not sure what the maths are at working out how probable these results are based on the range of values, and the amount of slots you're randomly loading them in to... Apologies for rambling there, I was typing out the thoughts in my head as I was thinking them... Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 22, 2007 Author Share Posted August 22, 2007 You are forgiven. I wasn't using the rand() function. I am using the shuffle() function. I just think it's because he can't update his browser. I know he is using an older version of IE (5, I think) and because our company is too damn cheap to put legal Windows software on the computers, no one can update to IE7. I don't have that problem . . . I use Firefox 2. I also notice that there is also a slight time delay for refreshing. If you push the refresh button too soon (like right after the screen finishes loading), then the "people" will not change. If you give it a few seconds after loading, then they change fine. As I tried to explain to "the man", the shuffle() function can only do so much with such a small number to be randomized. Of course if you hit the refresh button a million times per second (ha ha), then you are sure to get the same order of "people". Some day's your the windshield, and others your the bug. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 22, 2007 Share Posted August 22, 2007 based on the little you've said about "the man," i doubt giving him the math behind the possible combinations involved would help. for the 6 names into 3 slots, however, there are only 20 possible different combinations. i'm also sure there is more at play than simply the combinations - i imagine seeing a certain name in two different combinations might feel less random simply because of how much the name stuck in the viewer's mind from last time. long story short, i don't think there's much you can do to increase the randomness short of recording the previous combinations and ensuring that they don't overlap. however, this in itself reduces the randomness and eliminates the whole point. i've read that the mersenne twister (mt_rand) can have better performance than the traditional rand(); perhaps give that a shot and reorg the keys manually as opposed to using shuffle, and see if that satisfies him (even if this is really only a placebo). PS: i like the futurama reference. Quote Link to comment Share on other sites More sharing options...
Orio Posted August 22, 2007 Share Posted August 22, 2007 Are you using mt_srand() or srand()? Because if you use them in the wrong way, you may get the same results if you refresh very fast. If you do use mt_srand() or srand(), try removing it and see if it "more random". I am not sure if you actually think there's a problem with your script or you just posted this thread because you are pissed from what your boss told you, so ignore this post if the reason is the latter one. Orio. Quote Link to comment Share on other sites More sharing options...
hcdarkmage Posted August 22, 2007 Author Share Posted August 22, 2007 based on the little you've said about "the man," i doubt giving him the math behind the possible combinations involved would help.My point exactly! I am not sure if you actually think there's a problem with your script or you just posted this thread because you are pissed from what your boss told youThe latter. He doesn't understand what goes on with the web. He thinks that I can wave my Harry Potter wand and make everything comply to the wishes of a few whiners. I didn't mean for this post to become a topic of fixing the code, I just wanted to know if other people have had a problem with a "higher-up" telling you that they don't know how your code works. I've been through this before, and it is very, VERY annoying. You can't explain to the technically deficient that the preset algorithms are working fine, they just don't know why. Hence the title. I would love to tell "the man" to bite my shiny metal ***, but then I wouldn't be able to support my wife and two kids. I sure hope he can read this (though I doubt he goes to this forum)! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 23, 2007 Share Posted August 23, 2007 for the 6 names into 3 slots, however, there are only 20 possible different combinations. Wouldn't it be 120 combinations? Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 23, 2007 Share Posted August 23, 2007 120 permutations, 20 combinations. i assumed order didn't matter, since "the man"'s measure of how random it is likely wasn't affected by the order. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted August 23, 2007 Share Posted August 23, 2007 I hate counting; discrete math is a beast. Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 23, 2007 Share Posted August 23, 2007 PERMS N COMBS 4 LIFE! WOOOOOOOOORD. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.