random

random alphanumeric string into hexadecimal in Python

random alphanumeric string into hexadecimal in Python Question: I’m trying to turn an alphanumeric string into a hexadecimal number. The following code works as intended… A = "f8g9dsf9s7ff7s9dfg98d9fg97s06s6df5" B = int(A, 16) When I try create the alphanumeric dynamically it breaks and doesn’t get converted to hexadecimal number… A = ”.join(random.choices(string.ascii_lowercase + string.digits, k=34)) B …

Total answers: 1

Error with recursion from call "random.shuffle()"

Error with recursion from call "random.shuffle()" Question: Im trying to create a very simple blackjack game, and I think I’m almost done, but when I try to play the game I get an error: Traceback (most recent call last): File "c:Usersnils.edstromgithub-classroomNTI-Gymnasiet-Nackafebruariprojektet-Nilleni2Main.py", line 176, in <module> dealer = Dealer(player1) File "c:Usersnils.edstromgithub-classroomNTI-Gymnasiet-Nackafebruariprojektet-Nilleni2Main.py", line 107, in __init__ self._dealer …

Total answers: 1

Generating a random number (more than once) and using it inside two class functions

Generating a random number (more than once) and using it inside two class functions Question: I am building a GUI with tkinter where two buttons modify two text fields. One button chooses a random key from the example_dict and displays it in text1 , and the other reveals the corresponding value in text2 . I …

Total answers: 3

Error message: "object of type 'method' has no len()"

Error message: "object of type 'method' has no len()" Question: New to Python, and am trying to code a simple program which takes a user’s input of a music artist, searches for them in a CSV, looks at their genre, and uses this genre to find another, random, music artist of the same genre to …

Total answers: 1

How to generate a matrix of random values with zeros on the diagonal?

How to generate a matrix of random values with zeros on the diagonal? Question: I want get a matrix of random values with zero on main diagonal. Then the following codes work to integer values, but I actually want float value. def matriz_custo(n): numeros = sample(range(35,120+1),(n-1)*n) c = np.array([numeros[i:i+n] for i in range(0,len(numeros),n)]) np.fill_diagonal(c, 0) …

Total answers: 2

How to fix this problem when generating a pseudorandom number in Python?

How to fix this problem when generating a pseudorandom number in Python? Question: import hashlib import time def random(): hashtime = str(int(time.time() * (10 ** 6))) encoded = hashlib.new("sha3_512", hashtime.encode()) decoded = int(encoded.hexdigest(), 16) dcsmall = decoded / (10 ** (len(str(decoded)))) return (dcsmall) I tried this code to simulate the function random.random() without the module …

Total answers: 2

How to mimic rand() function of C in python?

How to mimic rand() function of C in python? Question: I am trying to reverse a logic of a C program with python. Part of the C program is the following : timeVar = time((time_t *)0x0) seed = (uint)timeVar; srand(seed); random_value1 = rand(); random_value2 = rand(); random_value3 = rand(); There is no upper bound given …

Total answers: 3

How to create rows of non-duplicating strings from a list?

How to create rows of non-duplicating strings from a list? Question: I want to create a 16X4 data frame with these coordinates as strings: "(.1,.1)","(-.1,-.1)","(-.1,.1)","(.1,-.1)". But, I do want not there to be duplicates. To put it another way, the script would output a 16X4 matrix/dataframe like this: "(.1,.1)","(-.1,-.1)","(-.1,.1)","(.1,-.1)" "(-.1,.1)","(-.1,-.1)","(.1,.1)","(.1,-.1)" "(-.1,-.1)","(.1,.1)","(-.1,.1)","(.1,-.1)" … In this way, …

Total answers: 1

prng,python, tkinter,need to change picture

prng,python, tkinter,need to change picture Question: I ran into this problem and don’t know how to solve it. When I press the "generate" button(self.gen), my picture 11 changes to picture 22. BUT I need the image 11 to NOT change when the button is clicked and an error occurs(messagebox.showerror pops up) OR so that after …

Total answers: 1

PRNG, python. 1 button – 2 function?

PRNG, python. 1 button – 2 function? Question: help me please. It is necessary that when the ‘Generate’ button(gen) is pressed, 2 functions (clicked1, gen1) are executed. But it only run clicked1. I read that I can use lambda; or create a separate function that includes the ones you need. But gen1 still fails. but …

Total answers: 1