Sudhi
Reputation
Next privilege 125 Rep.
Vote down
 Feb12 awarded Supporter Aug25 comment how random is ( rand() > rand() ? true : false ) Thats a very good point @Steven . Thank you very much for your insight and explanation. I must admit my lack of knowledge of what randomness means (as I expressed in my last update of question) and if one thing this exercise has taught me, that for every function that returns a bounded value, there will be some (overall) distribution in hiding. And it is this outcome that I must look/think for before getting into what function I should use. I thank you all again for your help. Aug25 accepted how random is ( rand() > rand() ? true : false ) Aug25 awarded Scholar Aug25 revised how random is ( rand() > rand() ? true : false ) Realized my mistake Aug25 comment how random is ( rand() > rand() ? true : false ) thanks for the clarification, I have realized my mistake, I think I confused distribution with pattern, and I must go back to my simulation as problem lies there, not in this function. After evaluating the needs, I should decide on the distribution. Sorry for this mess :( . Thank you all for your help. I hope to report back here (if I use the answer given below) with my findings. Aug25 awarded Commentator Aug25 comment how random is ( rand() > rand() ? true : false ) hmmm, partially agreed, let r=numOf(True)/numOf(False) then r~=1 (~ means nearly) for very large num. However, during my simulation, I observed for num < 3000 ; 0.6 < r < 1.3. I also discovered that changing %2 to %3 results in similar variance around r=2. I suspect that I will have to follow in your suggestions. When I do, I will report back here. Thanks. Aug25 comment how random is ( rand() > rand() ? true : false ) Kindly look at the updated question and comment. Thanks for your time. Aug25 comment how random is ( rand() > rand() ? true : false ) indeed, but the time itself is changing, so I dont know what is the exact time, hence the randomness. Or am I thinking totally wrong? Aug25 comment how random is ( rand() > rand() ? true : false ) can you please elaborate on it? Aug25 awarded Editor Aug25 revised how random is ( rand() > rand() ? true : false ) added personal observation Aug25 comment how random is ( rand() > rand() ? true : false ) darn! cant answer, here is the short of it. microtime() returns time in microseconds after the current second. So getResponse() { return ( microtime()*1000000 % 2 ); }. What do you think about it? Aug25 comment how random is ( rand() > rand() ? true : false ) thanks for your answer, it does seem a good option but I am not so keen on it as it entails keeping track of past results, which I don't want. How about this (see my answer below) Aug25 comment how random is ( rand() > rand() ? true : false ) @anon : no I do not want it to be fixed. See the thing is, I am running a simulation, and I do not want the overall distribution of True/False (whatever be the number of calls during simulation) to be a fixed ratio (which in this case is 50/50) Aug25 comment how random is ( rand() > rand() ? true : false ) What I want is the distribution of True(1) and False(0) for consecutive calls to the function should not be determined. e.g. if 1100001110001010101 (almost 50/50) is one outcome, then another call to function should not return 1010101000111000011 (reversed, just to make a point) which is again almost 50/50 . The ratio of True/False should be random for a given sample output of calls to the function. Aug25 comment how random is ( rand() > rand() ? true : false ) @Florian : perhaps, but I feel that my approach is wrong in the sense that I don't know what distribution I want. In fact, on a second thought, I do NOT want a particular distribution at all ! Every time I run the simulation, I do not want a particular distribution of True/False (say 50/50 in this case) Aug25 comment how random is ( rand() > rand() ? true : false ) Florian : How come? @Ricky : Err, I want random distribution? i.e. the probability of getting True or False should not depend on anything, perhaps I am getting this wrong. Let me put it in this way, I want getResponse() to return True or False (truly) randomly. Aug25 asked how random is ( rand() > rand() ? true : false )