Random Weapon with Rate Percentage
#4

Quote:
Originally Posted by coool
Посмотреть сообщение
Using some thing like "case 0..44" is in-efficient because it is like creating 44 if statements.
source: http://forum.sa-mp.com/showpost.php?...0&postcount=15
Код:
#include <a_samp>

public OnFilterScriptInit()
{
	new tick = GetTickCount();
	for(new i = 0; i < 1000000; i++)
	{
		switch(random(100))
		{
		    case 0..44:
		    {
		    }
		    case 45..89:
		    {
		    }
		    case 90..99:
		    {
		    }
		}
	}
	printf("Took: %d", GetTickCount() - tick);
	
	tick = GetTickCount();
	for(new i = 0; i < 1000000; i++)
	{
	    new val = random(100);
	    if(val >= 0 && val <= 44)
	    {
	    }
		else if(val >= 45 && val <= 89)
		{
		}
	    else if(val >= 90 && val <= 99)
	    {
	    }
	}
	printf("Took: %d", GetTickCount() - tick);
}
PHP код:
  Filterscript 'w.amx' unloaded.
Took92
Took
232
  Filterscript 
'w.amx' loaded
and its only one hundred.
Reply


Messages In This Thread
Random Weapon with Rate Percentage - by Dawkin - 24.07.2018, 10:03
Re: Random Weapon with Rate Percentage - by jlalt - 24.07.2018, 10:07
Re: Random Weapon with Rate Percentage - by coool - 24.07.2018, 10:11
Re: Random Weapon with Rate Percentage - by jlalt - 24.07.2018, 10:16
Re: Random Weapon with Rate Percentage - by Dawkin - 24.07.2018, 12:11
Re: Random Weapon with Rate Percentage - by NaS - 24.07.2018, 16:20

Forum Jump:


Users browsing this thread: 1 Guest(s)