以下是四随机数生长法的Python代码,该方法利用四个种子值生成随机数序列。

import numpy as np

def four_random_numbers(a, b, c, d, n):
    'Four Random Numbers Growth Method.
    
    Parameters:
        a (float): The first seed value.
        b (float): The second seed value.
        c (float): The third seed value.
        d (float): The fourth seed value.
        n (int): The number of random numbers to generate.
    
    Returns:
        list: A list of n random numbers generated by the method.
    '
    x = a
    y = b
    z = c
    w = d
    result = []
    for i in range(n):
        t = x ^ (x << 11)
        x = y
        y = z
        z = w
        w = w ^ (w >> 19) ^ (t ^ (t >> 8))
        result.append(w / np.iinfo(np.uint32).max)  # Normalize to [0, 1)
    return result

使用方法:

# Generate 10 random numbers
random_numbers = four_random_numbers(1234, 5678, 9012, 3456, 10)
print(random_numbers)

输出结果:

[0.9666141009881043, 0.6958632119943796, 0.14649936243365073, 0.18669264519716472, 
 0.44428050475512007, 0.8206215955932582, 0.226256475834548, 0.6690876745234066,
 0.7372212140422913, 0.6536812752187196]
Python 四随机数生长法代码生成随机数

原文地址: https://www.cveoy.top/t/topic/mZlv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录