AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with random choose... (https://forums.alliedmods.net/showthread.php?t=225048)

KaPaTeJIb 08-31-2013 08:14

Help with random choose...
 
1 Attachment(s)
Hi all again, I have a plugin, this is math games, each round is a competiton and if someone answers right, he'll win something. I want to include prize's random choice...Please help, thanks =)

Black Rose 08-31-2013 09:23

Re: Help with random choose...
 
Equal chance:
Code:
switch( random(4) ) {     case 0: // Do something     case 1: // Do something     case 2: // Do something     case 3: // Do something }
Percentages:
Code:
switch( random_num(1, 100) ) {     case 1 .. 5: // Do something, 5%     case 6 .. 49: // Do something, 44%     case 50: // Do something, 1%     case 51 .. 100: // Do something, 50% }

akcaliberg 08-31-2013 09:36

Re: Help with random choose...
 
random_prize = random_num( minimum_prize, maximum_prize )

??

KaPaTeJIb 08-31-2013 09:47

Re: Help with random choose...
 
Quote:

Originally Posted by Black Rose (Post 2025389)
Equal chance:
Code:
switch( random(3) ) {     case 0: // Do something     case 1: // Do something     case 2: // Do something     case 3: // Do something }

your method is better, thank you :)

ConnorMcLeod 08-31-2013 10:00

Re: Help with random choose...
 
Pay attention there is no case 3 in random(3)

random(3) is same as random_num(0, 2)

code can't generate errors but case 3 gonna never be called.

Black Rose 08-31-2013 11:43

Re: Help with random choose...
 
Sorry about that. I edited my post to avoid confusion.


All times are GMT -4. The time now is 19:01.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.