Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Jupyter 5 - Second Edition

You're reading from  Learning Jupyter 5 - Second Edition

Product type Book
Published in Aug 2018
Publisher
ISBN-13 9781789137408
Pages 282 pages
Edition 2nd Edition
Languages

Table of Contents (18) Chapters

Title Page
Packt Upsell
Contributors
Preface
Introduction to Jupyter Jupyter Python Scripting Jupyter R Scripting Jupyter Julia Scripting Jupyter Java Coding Jupyter JavaScript Coding Jupyter Scala Jupyter and Big Data Interactive Widgets Sharing and Converting Jupyter Notebooks Multiuser Jupyter Notebooks What's Next? Other Books You May Enjoy Index

Python random numbers in Jupyter


For many analyses, we are interested in calculating repeatable results. However, much of this analysis relies on some random numbers being used. In Python, you can set seed for the random number generator to achieve repeatable results with the random.seed() function.

In this example, we simulate rolling a pair of dice and look at the outcome. We would expect the average total of the two dice to be six, which is the half-way point between the faces.

The script we are using is as follows:

# using pylab statistics and histogram
import pylab
import random

# set random seed so we can reproduce results
random.seed(113)
samples = 1000

# declare our dataset store
dice = []

# generate and save the samples
for i in range(samples):
    total = random.randint(1,6) + random.randint(1,6)
    dice.append(total)

# compute some statistics on the dice throws
print("Throw two dice", samples, "times.")
print("Mean of", pylab.mean(dice))
print("Median of", pylab.median(dice...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}