Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python how to
#6
(Oct-08-2018, 12:08 PM)zhruser Wrote: Use this to simulate a result of rolling:

import random
r = int(random.random()*6)

Please, use python tags when post code.
Also, you may find interesting to read this
https://docs.python.org/3/library/random...r-integers

Quote:Changed in version 3.2: randrange() is more sophisticated about producing equally distributed values. Formerly it used a style like int(random()*n) which could produce slightly uneven distributions.

in this case one should use random.randint() in order to get equal distribution (i.e. given the required probability of 1/6).
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
python how to - by mmmmm - Oct-08-2018, 01:11 AM
RE: python how to - by ichabod801 - Oct-08-2018, 01:59 AM
RE: python how to - by DeaD_EyE - Oct-08-2018, 11:10 AM
RE: python how to - by volcano63 - Oct-08-2018, 12:11 PM
RE: python how to - by zhruser - Oct-08-2018, 12:08 PM
RE: python how to - by buran - Oct-08-2018, 12:26 PM

Forum Jump:

User Panel Messages

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