Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#Python, 42 bytes#
import random lambda n:1>random.random()*n
Edit: Removed the time.time() answer because of the distribution.
time.time()
#Python, 3642 bytes#
EditEdit: UsingRemoved the current time instead of randomtime.randomtime(), seven bytes are saved: answer because of the distribution.
randomtime.randomtime()
import time lambda n:1>time.time()%n
#Python, 36 bytes#
Edit: Using the current time instead of random.random(), seven bytes are saved:
random.random()
50 bytes if function is named:
import random def f(n):return 1>random.random()*n