Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random numbers, randint
#1
hello.
I got what I want in excel but it fades away so I thought I shoul try Python to do following:
Read 4 random numbers one by one, into a b c d until two conditions (a = 9 and b =20) is true.
Code attached refuse to use the logical and. It works like a logical or instead (stop running when one of conditions is achieved.

As a none repetition and using bytes (none values above 254), I have a feeling another function/methode might fit better?
Will execution of program run faster by using bytes instead of integers?

import tkinter
from random import randint
a=0
b=0
c=0
d=0
root_tk = tkinter.Tk()
window = root_tk
window.geometry("19x12+0+0")
window.minsize(19, 12)

while (a != 9) and  (b != 20):
    a=0
    b=0
    c=0
    d=0
    a = randint(1,16)
    b = randint(13,29)
    c = randint(16,34)
    d = randint(22,40)
    
print(a,b,c,d)

window.mainloop()[output][Running] python -u "d:\Python311\Scripts\randi.py"
9 26 18 31

[Done] exited with code=1 in 9.924 seconds

[Running] python -u "d:\Python311\Scripts\randi.py"
5 20 31 40

[Done] exited with code=1 in 5.363 seconds[/output]
Reply


Messages In This Thread
random numbers, randint - by janeik - Nov-27-2023, 12:46 AM
RE: random numbers, randint - by deanhystad - Nov-27-2023, 01:07 PM
RE: random numbers, randint, SOLVED - by janeik - Nov-27-2023, 05:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unexpected output while using random.randint with def terickson2367 1 567 Oct-24-2023, 05:56 AM
Last Post: buran
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,401 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,852 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,621 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
Sad Iterate randint() multiple times when calling a function Jake123 2 2,127 Feb-15-2022, 10:56 PM
Last Post: deanhystad
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,371 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  Help with a random.randint choice in Python booponion 5 2,869 Oct-23-2020, 05:13 PM
Last Post: deanhystad
  output a list of random numbers 'x' columns wide adityavpratap 4 3,090 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Can i prevent the random generator to generate already used numbers? MauserMan 3 2,947 Jan-05-2020, 04:44 PM
Last Post: MauserMan
  Inheriting, given number from randint is not working beLIEve 0 1,541 Oct-12-2019, 06:50 PM
Last Post: beLIEve

Forum Jump:

User Panel Messages

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