简体   繁体   English

如何修复值中的代码以便有随机数?

[英]How to fix the code in the values so that there are random numbers?

I don't know in programming, I need to fix the code, in the values of "M" and "L" I need to make random numbers consisting of 128 bits substituted?我不知道在编程中,我需要修复代码,在“M”和“L”的值中我需要替换由 128 位组成的随机数吗?

def extended_gcd(aa, bb):
    lastremainder, remainder = abs(aa), abs(bb)
    x, lastx, y, lasty = 0, 1, 1, 0
    while remainder:
        lastremainder, (quotient, remainder) = remainder, divmod(lastremainder, remainder)
        x, lastx = lastx - quotient*x, x
        y, lasty = lasty - quotient*y, y
    return lastremainder, lastx * (-1 if aa < 0 else 1), lasty * (-1 if bb < 0 else 1)

def modinv(a, m):
    g, x, y = extended_gcd(a, m)
    if g != 1:
        raise ValueError
    return x % m

M = 0x5FFDF9E967A054B02E0C56CDCF816A98
L = 0x45C42EF3369B5F069C57B4FF54F307F1

with open("results.txt", 'w') as f:
    print(hex(M*L), file=f)

If I understand the question correctly, all you'd have to do is:如果我正确理解了这个问题,那么您所要做的就是:

import random

with open("results.txt", "w") as f:
    for _ in range(num_of_rows):  # num_of_rows is the number of such results you want to store, replace it by the number
        M = random.randrange(16**32)
        L = random.randrange(16**32)
        print("0x{:066x}".format(M*L), file=f)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复代码,以便Python选择随机数 - How can I fix the code so Python will select the random number 如何对列表中的随机数样本进行编码,以便根据前面的数字生成的每个数字都遵循某些条件? - How can I code a sample of random numbers from a list, so that each number generated follows some condition depending on the preceding number? 如何更改我的代码,以使 output 中的值仅显示一次,而不是使用随机数多次显示? - How can I change my code so that the value in the output only shows once instead of more than one time using random numbers? 如何使用随机数值更新模板 - How to update a template with random numbers values 代码 &#39;for&#39; &#39;in&#39; &#39;not in&#39; 不起作用,如何修复以尊重在命令之前给出的答案? - Code 'for' 'in' 'not in' not working, how to fix so it respects answers give prior to commands? 如何修复我的代码以使其自动化? - How do I fix my code so that it is automated? 我该如何修复我的代码,使float变得可迭代? - How can i fix my code so a float be iterable? Python:如何修复此代码,使其可在Windows上使用? - Python: How can I fix this code so it works on Windows? 如何修复此数字排序python代码,以便其正常工作 - how to fix this number sorting python code so that it works correctly 如何在 Python 中生成带有一些 None 值的随机数列表? - How to generate list of random numbers in Python with some None values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM