random

Is this code capable of generating Cryptographically Secure Pseudo-Random Number Generator

Is this code capable of generating Cryptographically Secure Pseudo-Random Number Generator Question: I have a piece of code which generates a string of length 50 to 100 with random characters the code is : CharLIST = list(‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890’) def NEW(id_len): _id = ” while len(_id) < id_len: _id += random.choice(CharLIST) return _id NEW(random.randint(50, 100)) I expect …

Total answers: 1

While loop not executing passed the user input

While loop not executing passed the user input Question: #imports a library to call on random integers import random user_choice = ” random_num1 = 0 random_num2 = 0 random_num3 = 0 #keeps the loop going until ended by the user while user_choice != "n": user_choice = input(f’Welcome to the slot machine, would you like to …

Total answers: 1

How to make a random function without using any library?

How to make a random function without using any library? Question: I know that the way to produce random numbers from 0 to 1 (0.0 ≤ n < 1.0) can be done using a code like this in Python: import random print(random.random()) But I’m curious about how this function can be made and how it …

Total answers: 1

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