samedi 17 septembre 2022

TypeError: Message=int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'

So I am trying to make a random sample generator and I've got the following functions just for the sampling functions but it doesn't seem to work? (I'm trying to challenge myself by not using numpy or import random at all. However I am allowed to use import math

This is my pseudo number functions as a pre set-up incase something there is wrong:

def fakenpzeros(size):
    rows, cols = 1, size
    matrix = [([0]*cols) for i in range(rows)]
    return matrix
def pseudo_uniform(low = 0,
                   high = 1,
                   seed = 123456789,
                   size = 1):
    #generates me a number thats uniform between the high and low limits I've set
    return low + (high - low) * pseudo_uniform_good(seed = seed, size = size)
def pseudo_uniform_bad(mult = 5,
                       mod = 11,
                       seed = 1,
                       size = 1):
    U = fakenpzeros(size)
    x = (seed * mult + 1) % mod
    U[0] = x / mod
    for i in range(1, size):
        x = (x * mult + 1) % mod
        U[i] = x / mod
    return U
def pseudo_uniform_good(mult = 16807,
                        mod = (2 ** 31) - 1,
                        seed = 123456789,
                        size = 1):
    U = fakenpzeros(size)
    x = (seed * mult + 1) % mod
    U[0] = x / mod
    for i in range(1, size):
        x = (x * mult + 1) % mod
        U[i] = x / mod
    return U

Then this is my code for the random sampling

def randsamp(x):
    #Sets a seed based on the decimal point of your system clock, solves the rand.seed problem without introducing the random library
    t = time.perf_counter
    seed = int(10**9*float(str(t-int(t))[0:]))
    #makes an index of random smaples
    l = len(x)
    s = pseudo_uniform(low=0, high=l, seed=seed, size = 1)
    idx = int(s)
    return (x[idx])

I got an error of:

Message=int() argument must be a string, a bytes-like object or a real number, not 'builtin_function_or_method'

Could someone tell me what's wrong here? I've searched up this error but similar errors are like 'not list' or 'not NoneType' and none of their solutions seem to help me.

The specific line of code that is the problem is:

seed = int(10**9*float(str(t-int(t))[0:]))



Aucun commentaire:

Enregistrer un commentaire