Python Forum
Real Random Number Generator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Real Random Number Generator
#15
I've run a test on your code, based on a test the I did (some time back) for the random.randint() function.

I've incorporated your code (that you posted at the beginning of this thread) in a function that I've named prng() and clearly marked the code that you posted, and commented the changes needed in order to have it work with my app.

In order to get some 'density', with my app, it was necessary to have an iteration count up at 10.000.000, which means that the process takes about 30 minutes to run. By contrast, using the random.randint() function as is (that is to say, with a zero to 800 range), an iteration count of 100.000 is as high as you need, because if you go much higher than that, the 800 x 600 window would be completely filled and as such, no pattern would be seen.

The point here is that if one can see a 'pattern', then the results are not random, but if the window is filled with what looks like 'noise', then there is some semblance of 'randomness'.

I've posted a screen grab here, so that you (or anyone else) does not have to wait around for a half hour, to see the results, but, of course, one can choose to do that. Simply running this, with the first set of r1 and r2 takes, seconds, with the iteration count set to 100000.

As you can see, from the screen grab, there is a pattern, which (to my mind) suggests that this is far from a random number generator.

Is this a valid test, or is it flawed?

import random
import tkinter as tk
from tkinter import Canvas

#=======<WT550 CODE START>======#
import time
number_of_needed_numbers = 10000
lower_value = 0
upper_value = 800  # I've changed this from 1 to 800, so that it fits this app
short_time = 0.00000000000001
OFFSET_TIME = 0.03258312993051001

def prng():
    start_time = time.time()
    start_time2 = start_time - OFFSET_TIME
    time.sleep(short_time)
    end_time = time.time()
    total_seed = end_time - start_time2
    random.seed(total_seed)
    random_number = random.randint(lower_value, upper_value)
    return random_number
#======<WT550 CODE STOP>=======#

root = tk.Tk()

# creat the root window
root.geometry("800x600")
root.title("Random Plot")
root.resizable(False, False)

C = Canvas(root, bg="#BABDB6", height=600, width=800)

for p in range (100000): # change this to > 1000000 to use the prng() function.

    # use this with a iteration of apx 100000
    r1=random.randint(0,800)
    r2=random.randint(0,800)

    # ... or this with a iteration of 10000000 to reproduce what I've posted here
    #r1 = prng()
    #r2 = prng()

    r3=r1+1
    r4=r2+1
    p = C.create_rectangle(r1,r2,r3,r4, fill='black')

C.grid()

root.mainloop()
Gribouillis likes this post

Attached Files

Thumbnail(s)
   
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply


Messages In This Thread
Real Random Number Generator - by woodturner550 - Jan-02-2024, 11:54 PM
RE: Real Random Number Generator - by Gribouillis - Jan-03-2024, 08:36 AM
RE: Real Random Number Generator - by woodturner550 - Jan-03-2024, 06:46 PM
RE: Real Random Number Generator - by DeaD_EyE - Jan-04-2024, 09:36 PM
RE: Real Random Number Generator - by woodturner550 - Jan-05-2024, 12:34 AM
RE: Real Random Number Generator - by woodturner550 - Jan-06-2024, 04:24 AM
RE: Real Random Number Generator - by woodturner550 - Jan-08-2024, 11:43 PM
RE: Real Random Number Generator - by DeaD_EyE - Jan-10-2024, 04:18 PM
RE: Real Random Number Generator - by woodturner550 - Jan-11-2024, 12:43 AM
RE: Real Random Number Generator - by woodturner550 - Jan-13-2024, 02:13 AM
RE: Real Random Number Generator - by woodturner550 - Jan-31-2024, 01:56 AM
RE: Real Random Number Generator - by rob101 - Jan-31-2024, 03:12 AM
RE: Real Random Number Generator - by woodturner550 - Jan-31-2024, 03:20 AM
RE: Real Random Number Generator - by rob101 - Jan-31-2024, 09:59 AM
RE: Real Random Number Generator - by DeaD_EyE - Jan-31-2024, 11:44 AM
RE: Real Random Number Generator - by woodturner550 - Jan-31-2024, 06:04 PM
RE: Real Random Number Generator - by rob101 - Jan-31-2024, 06:25 PM
RE: Real Random Number Generator - by DeaD_EyE - Jan-31-2024, 06:47 PM
RE: Real Random Number Generator - by woodturner550 - Jan-31-2024, 07:22 PM
RE: Real Random Number Generator - by rob101 - Jan-31-2024, 07:41 PM
RE: Real Random Number Generator - by DeaD_EyE - Feb-01-2024, 03:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Passcode Generator function romeo777 2 2,673 Jan-06-2021, 01:46 PM
Last Post: buran
  random two-word domain name generator rootVIII 0 2,167 Aug-06-2019, 03:15 AM
Last Post: rootVIII
  Infinate Number Generator Larz60+ 6 4,276 Sep-18-2018, 06:23 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020