Jump to content
×
×
  • Create New...

PY Function - Random Words


Recommended Posts

M2 Download Center

Hidden Content

    Give reaction to this post to see the hidden content.
( 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))

 

  • Love 4
Link to comment
  • 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
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
  • 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

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Read our Rules
  • Activity

    1. 1

      Fix CursorImage 'NoneType' object is not callable.

    2. 0

      [Land of Heroes] We are looking for Game / Game Economy Designers

    3. 177

      Render Target Remastered

    4. 1

      MySQL stop when start server

    5. 0

    6. 59

      Emoji in TextLine

    7. 1

      MySQL stop when start server

  • Recently Browsing

    No registered users viewing this page.

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.