SA-MP Forums 4digit random numbers
 New Account Members List Search Today's Posts Mark Forums Read

 18/01/2011, 11:43 AM #1 THE_KNOWN Gangsta   Join Date: Dec 2010 Posts: 702 Reputation: 60 4digit random numbers as the title says code a random number system? i want it to give a random bank pin and it should only be 4digit and non repeating
 18/01/2011, 11:54 AM #2 Universal Huge Clucker     Join Date: Jan 2010 Posts: 449 Reputation: 27 Re: 4digit random numbers use: Above the main(): pawn Code: new pBankPin [ MAX_PLAYERS ]; And heres the functions: pawn Code: stock GenerateBankPin() { new pin =  random(9999); return pin;}stock GivePlayerBankPin ( playerid ) {new bpin = GenerateBankPin();for ( new i = 0; i < MAX_PLAYERS ; i++ ) { if ( IsPlayerConnected ( i ) && pBankPin [ i ] ==  bpin ) {  bpin = GenerateBankPin(); }} return bpin;} Havent tested it.
 18/01/2011, 11:57 AM #3 Macluawn Gangsta     Join Date: Aug 2010 Location: Latvia Posts: 613 Reputation: 78 Re: 4digit random numbers with your example the pin could be 3digit, 2digit and even 1digit number. use Code: pin = 1000+random(8999); with this the pin minimum can be 1000 and maximum of 9999 (1000+8999=9999) My version of your code - Code: stock GenerateBankPin(playerid) { new pin = 1000+random(8999); //generates a number for ( new i = 0; i < GetMaxPlayers() ; i++ ) //loops through all the server player slots (defined in server.cfg) { if ( IsPlayerConnected ( i ) && pBankPin [ i ] == bpin && i!=playerid) pin = 1000+random(8999); //checks if player in that slot is connected and if its pin is the same as the playerid's then it generates a new pin. } return pin; } This isn't the best sollution offcourse and in some cases the number may be the same.
 18/01/2011, 11:58 AM #4 THE_KNOWN Gangsta   Join Date: Dec 2010 Posts: 702 Reputation: 60 Re: 4digit random numbers afaik random only generates numbers ranging between 0 to max(9999) so i think this wont work (havent tested).
 18/01/2011, 11:59 AM #5 THE_KNOWN Gangsta   Join Date: Dec 2010 Posts: 702 Reputation: 60 Re: 4digit random numbers @macluan how do make a 8digit number which wont repeat?(for phonenumbers)
 18/01/2011, 12:01 PM #6 Macluawn Gangsta     Join Date: Aug 2010 Location: Latvia Posts: 613 Reputation: 78 Re: 4digit random numbers the same as my other example, but changing the minimum and the maximum ammount. Code: phonenumber = 10000000+random(89999999);
 18/01/2011, 12:13 PM #7 THE_KNOWN Gangsta   Join Date: Dec 2010 Posts: 702 Reputation: 60 Re: 4digit random numbers but how can i make it exclude already selected nos?
 18/01/2011, 12:14 PM #8 THE_KNOWN Gangsta   Join Date: Dec 2010 Posts: 702 Reputation: 60 Re: 4digit random numbers nvm just understood. btw thanks for the help man

 Thread Tools Display Modes Linear Mode

 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 Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post psoftware Help Archive 7 31/12/2010 06:14 PM Rainbow_Six Help Archive 4 21/10/2010 06:08 PM Torran Help Archive 1 02/04/2010 07:51 PM SiJ Help Archive 6 09/08/2009 02:14 PM *BueNoOo* Help Archive 11 18/06/2009 04:13 PM

All times are GMT. The time now is 09:08 AM.

 -- (EN) English -- (RU) Русски SA-MP - Archive - Top