Jump to content

PY Function - Random Words


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

Spoiler

2328189c5fa30e5cd1111eacad5dd147a4d7d4.g

Perhaps it will be useful for some people for various systems.

Have fun.

#	onPressKeyDict[app.DIK_F5]	= lambda : self.Print() # For test function @root/game.py
def Print(self):
	import app, chat
	list = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" # Set list
	maxStr = 10 # Set the maximum number of characters
	k = ""
  
	for v in xrange(maxStr): k = k + list[app.GetRandom(0, len(list) - 1)]
	chat.AppendChat(chat.CHAT_TYPE_INFO, "Result word: %s" % str(k))

 

  • Metin2 Dev 1
  • Love 4
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

  • 1 year later...
  • Honorable Member

c++ version

#include <iostream>
#include <ctime>
using namespace std;
int main()
{
    srand( time( NULL ) );
    char list[] = {"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y"};
    int maxStr = 10;
    std::string random_word = "";
    for (int i = 0; i < maxStr; ++i) {
        int randa = rand() % sizeof(list);
        if (list[randa] == ',') {
            i--;
            continue;
        }
        random_word += list[randa];
    }
    cout<<random_word;

    return 0;
}

 

 

Link to comment
Share on other sites

1 godzinę temu, Mali61 napisał:

c++ version


#include <iostream>
#include <ctime>
using namespace std;
int main()
{
    srand( time( NULL ) );
    char list[] = {"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y"};
    int maxStr = 10;
    std::string random_word = "";
    for (int i = 0; i < maxStr; ++i) {
        int randa = rand() % sizeof(list);
        if (list[randa] == ',') {
            i--;
            continue;
        }
        random_word += list[randa];
    }
    cout<<random_word;

    return 0;
}

 

for what you used comma in table??

Link to comment
Share on other sites

  • Bot
import random, string

def Print(maxStr):
    list = [x for x in string.digits + string.ascii_letters]
    k = ""

    for v in range(0, maxStr): k += list[random.randint(0, len(list) - 1)]
    print("Result word: %s" % str(k))

Print(10)

For Python3 + anyone, who wants to use it in an extern program.

Nice idea, not that bad tbh. ^^

 

King Regards

Cyber

english_banner.gif

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.