Python‎ > ‎random‎ > ‎

random.random()

http://www.adilwaseem.com/

Introduction
The random() method of random.

Syntax
random.random()-> random in range(0, 1)

Parameters
None

Examples
The button command function is used to invoke the message box to display the random value.
from tkinter import*

master = Tk()
master.title("Random Widget")

def random_value():
    import random
    random1=random.random()
    messagebox.showinfo("Random Value is", random1)

labelframe=LabelFrame(master, fg="red", font=14, text="Random value generator")
labelframe.pack(side=BOTTOM)

button = Button(labelframe, text = "Click here", fg="blue", command = random_value)
button.pack(side=BOTTOM)

label = Label(labelframe, text = "Click on button to generate random value")
label.pack(side=BOTTOM)

master.mainloop()





operator.neg(random)
The return with negative random value.
import operator
import random
random1=random.random()
print(operator.neg(random1))
>>> 
-0.9279674230152819
>>> 


The method return with random multiplication with value of input().
import random
x=input("Please enter your number: ")
y=int(x)
z=random.random()
print("your random number is", z)
print("Multiplication of the random number with your number is: ",y *z )

>>> 
Please enter your number: 44
your random number is 0.3820807373077786
Multiplication of the random number with your number is: 16.811552441542258
>>>

Comments