performance - Fastest way to generate and check numbers in PHP? -
I need some help in creating numbers in PHP, for example by checking that if the number is below 100 Then give 0.1 points. It is for a coin system that is called when some actions are used in flash games.
I want to do it in the fastest time and this is the code that I am using before testing it. I update it on the main server for the game.
& lt ;? Php $ coins = 0; $ Rand = rand (0, 1000); If ($ rand <50) {$ Coins = $ Coins + 0.01; } If ($ RAND & LT; 100 & amp; RAND & gt; 50) {$ Coins = $ Coins + 0.2; } If ($ rand> 100 & amp; amp; amp; $ Rand <200) {$ coins = $ coins + 0.2; } If ($ rand> 500) {$ Coins = $ Coins + 0.5; } Echo "coins generated coins \ n"; ? & Gt; Sorry, if someone does not understand my search in some words, then I am asking how fast I can do it and someone has a suggestion for it. ? Instead of using rand () , consider using the
. From Docs: Many random number generators of old labels have suspicious or unknown features and are slow. By default, the PHP rand () function uses libc random number generator with the function. The Mt_rand () function is a drop-in replacement for this. It uses a random number generator, which will be four times faster than the »One» Marson Twister, which provides the random number Average libc rand (). Apart from this, there is another similar thread to discuss another topic here: I'm not sure what kind of optimization you have here Looking forward and would like to repeat the comments of Frank Farmer from that discussion:
Why are you so concerned about the speed with this special operation? Have you done a profile? How long can you survive by choosing one on another? ... Allow me to direct more: This does not make a significant difference. We are talking about a difference measured in nanosecond
Comments
Post a Comment