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

Solved array


Post New Thread Reply   
 
Thread Tools Display Modes
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 02-01-2018 , 17:50   Re: array
Reply With Quote #11

Quote:
Originally Posted by E1_531G View Post
random(2) will generate only 0 and 1.
Uhh, didn't know that. So, if I wanna use a random value between 0 and 2, I should use random_num(0, 2) instead of random(3), r?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 02-01-2018 , 18:11   Re: array
Reply With Quote #12

Quote:
Originally Posted by EFFx View Post
Uhh, didn't know that. So, if I wanna use a random value between 0 and 2, I should use random_num(0, 2) instead of random(3), r?
You will get the same results with both.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-02-2018 , 02:09   Re: array
Reply With Quote #13

The range of random(x) is [0, x).
__________________
klippy is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 02-02-2018 , 04:18   Re: array
Reply With Quote #14

this doesn't make sense. So if I want the number between 0 and 2, I have to generate a random number between 0 and 3? That's a one awkward native.
__________________
retired chump
DjSoftero is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-02-2018 , 04:58   Re: array
Reply With Quote #15

Quote:
Originally Posted by DjSoftero View Post
this doesn't make sense. So if I want the number between 0 and 2, I have to generate a random number between 0 and 3? That's a one awkward native.
Javascript: https://www.w3schools.com/jsref/jsref_random.asp
C#: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
Rust: https://doc.rust-lang.org/rand/rand/...thod.gen_range

There are many languages that have a function in their standard library that generates a number in range [min, max) because it makes total sense; it's not awkward at all.
__________________
klippy is offline
DjSoftero
Veteran Member
Join Date: Nov 2014
Location: Lithuania
Old 02-02-2018 , 05:00   Re: array
Reply With Quote #16

Quote:
Originally Posted by KliPPy View Post
Javascript: https://www.w3schools.com/jsref/jsref_random.asp
C#: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
Rust: https://doc.rust-lang.org/rand/rand/...thod.gen_range

There are many languages that have a function in their standard library that generates a number in range [min, max) because it makes total sense; it's not awkward at all.
I guess the description should be somewhat changed Returns a random number between 0 and a specified upper bound https://www.amxmodx.org/api/core/random
__________________
retired chump
DjSoftero is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-02-2018 , 05:01   Re: array
Reply With Quote #17

Quote:
Originally Posted by DjSoftero View Post
I guess the description should be somewhat changed Returns a random number between 0 and a specified upper bound https://www.amxmodx.org/api/core/random
In the parameter description it says "Exclusive upper bound". It's clear how the function works.
__________________
klippy is offline
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 02-02-2018 , 10:11   Re: array
Reply With Quote #18

Quote:
Originally Posted by DjSoftero View Post
Code:
client_print(id, print_chat, "%i", array[random(sizeof(array)-1)][random(sizeof(array[])-1)]
i`m on the phone, so some brackets might be missing
Hi DjSoftero,
Thanks for reply.

This always gives me 1241 output
what i want ?
PHP Code:
new const array[][] =
{
{
1241,2414,3744}, // first data
{1654,2754,3534// second data
}; 
it will choose random from above
suppose first time it will print
1241 2414 3744
second time it will print
1654 2754 3534
Thanks

Last edited by indraraj striker; 02-02-2018 at 10:11.
indraraj striker is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 02-02-2018 , 10:50   Re: array
Reply With Quote #19

Code:
new i = random(sizeof(array)); client_print(id, print_chat, "%d, %d, %d", array[i][0], array[i][1], array[i][2]);

Last edited by Black Rose; 02-02-2018 at 16:14.
Black Rose is offline
indraraj striker
Veteran Member
Join Date: Mar 2014
Location: Under the water
Old 02-02-2018 , 11:01   Re: array
Reply With Quote #20

Hi Black Rose,
Thanks for reply.

Thanks it's working.
#solved

Last edited by indraraj striker; 02-02-2018 at 11:06.
indraraj striker 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 19:21.


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