Random.randint()

I was considering just how random (or pseudorandom in fact) the random.randint() method is and came up with this:

import random
import tkinter as tk
from tkinter import Canvas

root = tk.Tk()

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

C = Canvas(root, bg="#BABDB6", height=400, width=800)
n1 = 10
n2 = 780

for y in range (5, 400, 5):
    for x in range(100):
        r = random.randint(n1,n2)
        a = C.create_rectangle(r, y, r, y, fill = 'black')
        C.grid()
root.mainloop()

Fairly random I’d say.

I’ve reworked this so as to get more of a scatter pattern, rather than a linear one.

import random
import tkinter as tk
from tkinter import Canvas

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 (10000):
    r1=random.randint(0,800)
    r2=random.randint(0,800)
    r3=r1+1
    r4=r2+1
    p = C.create_rectangle(r1,r2,r3,r4, fill='black')
    
C.grid()

root.mainloop()