Monday, April 28, 2025

Number Stations as Screensaver - Random Number Generator - Python

This Python script will emulate number station stream. You can use it as screensaver or just for experiments. 

Random module is for, well, randomness, and time module is for pause between generations.

import random, time

While True is needed so this random number generator will work constantly.


Variables rn from 1 to 4 will hold random number from 1000 to 9999. 

    rn_1 = random.randint(1000, 9999)
    rn_2 = random.randint(1000, 9999)
    rn_3 = random.randint(1000, 9999)
    rn_4 = random.randint(1000, 9999)

After that, you can just print variables, or, of you need more numbers just multiply existing variables with some constant as 0.8 or something.

    print(rn_1, '\t', int(rn_1*0.8), '\t',
          int(rn_2), '\t',int(rn_2*0.8), '\t',
          int(rn_3), '\t',int(rn_3*0.8), '\t',
          int(rn_4), '\t',int(rn_4*0.8), '\t')
    time.sleep(1)

You can have as menu random numbers as you like :)

Full Script: 

import random, time

while True:
    rn_1 = random.randint(1000, 9999)
    rn_2 = random.randint(1000, 9999)
    rn_3 = random.randint(1000, 9999)
    rn_4 = random.randint(1000, 9999)
    
    print(rn_1, '\t', int(rn_1*0.8), '\t',
          int(rn_2), '\t',int(rn_2*0.8), '\t',
          int(rn_3), '\t',int(rn_3*0.8), '\t',
          int(rn_4), '\t',int(rn_4*0.8), '\t')
    time.sleep(1)

Learn More:

Free Python Programming Course
Python Examples
Python How To
Python Modules 

YouTube WebDevPro Tutorials

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...