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

[HOW TO] Retrieve random values from an array without retreiving the same twice


Post New Thread Reply   
 
Thread Tools Display Modes
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-04-2011 , 22:26   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #51

The variable isn't increased at all, even after server_print() is called?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-04-2011 , 22:55   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #52

it did increased, but the expression take the value before it increased as the value
here is a small c test
Code:
#include "stdafx.h"
#include "stdlib.h"

int foo(int i)
{
	return i++;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int i = 0;
	printf("%d\n", i++);
	printf("%d\n", i);
	printf("%d\n", foo(i));

	system("pause");
}
the result is
0
1
1
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-04-2011 , 22:59   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #53

Quote:
Originally Posted by jim_yang View Post
it did increased, but the expression take the value before it increased as the value
here is a small c test
Code:
#include "stdafx.h"
#include "stdlib.h"

int foo(int i)
{
	return i++;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int i = 0;
	printf("%d\n", i++);
	printf("%d\n", i);
	printf("%d\n", foo(i));

	system("pause");
}
the result is
0
1
1
Yes, I understand pre/post increment differences.
When I initially asked my question, I meant that the variable wasn't being incremented at all, even after the printing.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-04-2011 , 23:03   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #54

really? if so, that's the bug from complier.
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 08-05-2011 , 04:53   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #55

I remembered the increment was never done but at least now it seems it is done. I can verify a bug in compilers because at least the values the expression returns are rubbish. I would though not be surprised if this was already corrected in Compuphase.

Code:
new a[ 1 ];     for( new i; i < 10; i++ )     server_print( "%i   %i", a[ 0 ]++, a[ 0 ] );
PHP Code:
0   1
822083584   2
3211264   3
12544   4
49   5
771751936   6
3014656   7
11776   8
46   9
805306368   10 

Last edited by SnoW; 08-05-2011 at 04:57.
SnoW is offline
Send a message via MSN to SnoW
jim_yang
Veteran Member
Join Date: Aug 2006
Old 08-05-2011 , 05:45   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #56

really interesting stuff, I just have downloaded the newest version from pawn official site, same problem.
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>
jim_yang is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 08-05-2011 , 05:52   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #57

Quote:
Originally Posted by jim_yang View Post
really interesting stuff, I just have downloaded the newest version from pawn official site, same problem.
Then this is going to be fun, actually worthwhile.
SnoW is offline
Send a message via MSN to SnoW
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 08-05-2011 , 11:09   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #58

Someone should test the same on SourcePawn compiler.
__________________
xPaw is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-05-2011 , 12:57   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #59

I've noticed the same bug when using an incrementor operator, it only occurs for me when the incrementing (var++) is done as a param for string formatting. I don't remember if it only affects arrays as snow posted or if it also affects normal variables.
__________________

Last edited by Bugsy; 08-05-2011 at 13:02.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-05-2011 , 14:09   Re: [HOW TO] Retrieve random values from an array without retreiving the same twice
Reply With Quote #60

Quote:
Originally Posted by Bugsy View Post
I've noticed the same bug when using an incrementor operator, it only occurs for me when the incrementing (var++) is done as a param for string formatting. I don't remember if it only affects arrays as snow posted or if it also affects normal variables.
Quote:
Originally Posted by Exolent[jNr] View Post
It does the same thing with dynamic natives.

Code:
new count; public plugin_natives( ) {     register_native( "increase", "_increase" ); } public _increase( ) {     return count++; }

That won't work properly.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 17:35.


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