[Python] How do I generate a different string each time x changes in my sympy summation?

Discussão em 'Python' iniciado por Stack, Janeiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with sympy in python and I am using a sympy summation to generate different combinations of string values.

    I want the code to generate different combinations of strings using the random module for each value of x in my sympy summation.

    The code I'm using is:

    from sympy import summation, Piecewise, symbols, Eq, Ge,solve, Le
    import sys
    import itertools
    import string
    import random

    sys.setrecursionlimit(300000000)


    x = symbols('x')

    # Create a dictionary to map numbers to characters
    def checksum1(args2):
    def generate_random_string(min_length, max_length):
    length = random.randint(min_length, max_length)
    characters = string.printable.strip()
    return ''.join(random.choices(characters, k=length)) #change this to generate a different random one for each x

    client = generate_random_string(60, 200)

    try:

    account = ord(client)
    return 1
    except Exception:
    return 0


    m = Piecewise(
    (checksum1(x), Eq(checksum1(x), 1)),
    (0, True)
    )

    result = summation(m, (x, 1, 900))
    print(result)


    In the code, I want to use a different random string each time in the function checksum1. It only generates one random string and then it stops there. Each value of x should have a different random string until all of the random values have been exhausted. Can someone show me what to do?

    Continue reading...

Compartilhe esta Página