<jupyter_start><jupyter_text>Exercise 1<jupyter_code>gen = default_rng(SEED)
gen.standard_normal(10)
gen.normal(size=10)
# Parameters are mean and scale, i.e., stdandard deviation
gen.normal(3, 3, size=10)
gen.random(10)
gen.uniform(0, 1, size=10)
gen.uniform(-1, 1, size=10)
gen.gamma(1, 2, size=10)
# mu, sigma
gen.lognormal(0.8, 0.2, size=10)<jupyter_output><empty_output><jupyter_text>Exercise 2<jupyter_code>gen = default_rng(SEED)
first = gen.integers(0, 11, size=10)
first
gen = default_rng(SEED)
second = gen.integers(0, 11, size=10)
second
first - second<jupyter_output><empty_output><jupyter_text>Exercise 3<jupyter_code>sigma = np.array([[1, -0.5], [-0.5, 1]])
mvn = gen.multivariate_normal([0, 0], sigma, size=10000)
cov = np.cov(mvn.T)
cov
cov - sigma<jupyter_output><empty_output><jupyter_text>Exercise 4<jupyter_code>from numpy.random import PCG64, Generator, SeedSequence

ss = SeedSequence(SEED)
pcg = PCG64(ss)
gen = Generator(pcg)
pcg5 = gen.random(5)
pcg5
gen = default_rng(SEED)
gen.random(5)
from numpy.random import Philox

ss = SeedSequence(SEED)
philox = Philox(ss)
philox_gen = Generator(philox)
philox5 = philox_gen.random(5)
philox5
pcg5 - philox5<jupyter_output><empty_output><jupyter_text>Exercise 5<jupyter_code>ss = SeedSequence(SEED)
children = ss.spawn(2)
gen = default_rng(ss)
child_gen1 = default_rng(children[0])
child_gen2 = default_rng(children[1])
# No spawn key
ss
# See the spawn key
children[0]
# Different spawn key
children[1]
gen.random(5)
child_gen1.random(5)
child_gen2.random(5)<jupyter_output><empty_output><jupyter_text>Exercise 6<jupyter_code>np.random.seed(int(10 ** 5 * np.pi))
np.random.random_sample(5)
np.random.seed(int(10 ** 5 * np.pi))
np.random.random_sample(5)<jupyter_output><empty_output><jupyter_text>Exercise 7<jupyter_code>state = np.random.get_state()
np.random.random_sample(5)
np.random.set_state(state)
np.random.random_sample(5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1466321243523316, 'fraction_numerical': 0.04818652849740933, 'mean_word_length': 7.620535714285714, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '443439', 'license': 'CC0-1.0', 'n_tokens_mistral': 871, 'n_tokens_neox': 820, 'n_words': 134, 'path': 'solutions/chapter20/simulation.ipynb', 'repo_name': 'bashtage/python-for-econometrics-statistics-data-analysis', 'size': '1930'}