Raised This Month: $51 Target: $400
 12% 

Solved random


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 01-21-2018 , 01:41   random
Reply With Quote #1

random_num(0, 30)

how can i do that ? don't consider 13 and 22 number
Thanks

Last edited by indraraj striker; 01-22-2018 at 01:45.
indraraj striker is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 01-21-2018 , 05:34   Re: random
Reply With Quote #2

Code:
do (a = random_num(0, 30)) while (a == 13 || a == 22);
Does this helps?
__________________
Relaxing is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2018 , 07:13   Re: random
Reply With Quote #3

Quote:
Originally Posted by Relaxing View Post
Code:
do (a = random_num(0, 30)) while (a == 13 || a == 22);
Does this helps?
No its a bad code
And might cause infinite loop causing a crash...

Fill out the numbers you want into an array then do a random taking array size as parameter in the random operation
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-21-2018 , 08:22   Re: random
Reply With Quote #4

Quote:
Originally Posted by Natsheh View Post
No its a bad code
And might cause infinite loop causing a crash...

Fill out the numbers you want into an array then do a random taking array size as parameter in the random operation
The chance of that happening in that span with so few exceptions is so small that it's not even worth caring about.
Black Rose is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-21-2018 , 08:25   Re: random
Reply With Quote #5

https://forums.alliedmods.net/showthread.php?t=302993
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2018 , 08:26   Re: random
Reply With Quote #6

Quote:
Originally Posted by Black Rose View Post
The chance of that happening in that span with so few exceptions is so small that it's not even worth caring about.
Why preferring to chooses a method that it has a chance of error over a fixed one.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-21-2018 , 08:45   Re: random
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Why preferring to chooses a method that it has a chance of error over a fixed one.
You have to concider the probability of this.

Randomizing a temporary filename with 6 characters, assuming we use all lowercase, uppercase and numeric characters and want to avoid an infinite loop we would end up with 26+26+10 different characters ^6, therefor 56 800 235 584 different options. Saving those in an array of 7 cells each since you need to null-terminate that's 1.45Terabyte of memory.
Would you use the same method of generating it? No you wouldn't because it's illogical. You would waste more power preparing the array then using it.

You have to draw the line somewhere and if the exceptions are static and the probability to hit them in one cycle is less than 20-30% then the probability for an infinte loop is WAY too low. If you follow the rules of probability you would hit a correct number in 3-4 loop cycles.

By preparing an array in cases they are not required you are actually wasting CPU and memory for no reason than to feel good about yourself.

If the exceptions however are dynamic then I would definitely use an array.
Black Rose is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-21-2018 , 09:02   Re: random
Reply With Quote #8

Quote:
Originally Posted by Black Rose View Post
You have to concider the probability of this.

Randomizing a temporary filename with 6 characters, assuming we use all lowercase, uppercase and numeric characters and want to avoid an infinite loop we would end up with 26+26+10 different characters ^6, therefor 56 800 235 584 different options. Saving those in an array of 7 cells each since you need to null-terminate that's 1.45Terabyte of memory.
Would you use the same method of generating it? No you wouldn't because it's illogical. You would waste more power preparing the array then using it.

You have to draw the line somewhere and if the exceptions are static and the probability to hit them in one cycle is less than 20-30% then the probability for an infinte loop is WAY too low. If you follow the rules of probability you would hit a correct number in 3-4 loop cycles.

By preparing an array in cases they are not required you are actually wasting CPU and memory for no reason than to feel good about yourself.

If the exceptions however are dynamic then I would definitely use an array.
Its dynamic..

But the loop still has a error percentage.

Yeah i would use more memory inorder to avoid the error
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 01-21-2018 at 09:08.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 01-21-2018 , 09:19   Re: random
Reply With Quote #9

Don't rely on random for such things. You can get the same result 10times and it's perfectly fine since it is a random result, it depends on prediction/distribution/concurrency etc
Also a critical part is how random_num it is implemented in amxx(i'm too lazy to search about it), which random engine/generator is used. So you better use what @Natsheh suggested since it is the best and safe/deterministic solution.

Last edited by Clauu; 01-21-2018 at 09:33.
Clauu is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-21-2018 , 11:44   Re: random
Reply With Quote #10

This has already been discussed in another topic, do a search.
__________________








CrazY. is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:44.


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