Skip to content

Commit 5c2c950

Browse files
Update rng usage in opt_transport.md
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dba5555 commit 5c2c950

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

lectures/opt_transport.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,12 @@ arr = np.arange(m+n)
432432
```{code-cell} ipython3
433433
sol_found = []
434434
cost = []
435+
rng = np.random.default_rng()
435436
436437
# simulate 1000 times
437438
for i in range(1000):
438439
439-
np.random.shuffle(arr)
440+
rng.shuffle(arr)
440441
res_shuffle = linprog(C_vec, A_eq=A[arr], b_eq=b[arr])
441442
442443
# if find a new solution
@@ -709,18 +710,18 @@ Locations are assigned randomly.
709710
def build_nodes_of_one_type(group='p', n=100, seed=123):
710711
711712
nodes = []
712-
np.random.seed(seed)
713+
rng = np.random.default_rng(seed)
713714
714715
for i in range(n):
715716
716717
if group == 'p':
717718
m = 1/n
718-
x = np.random.uniform(-2, 2)
719-
y = np.random.uniform(-2, 2)
719+
x = rng.uniform(-2, 2)
720+
y = rng.uniform(-2, 2)
720721
else:
721722
m = betabinom.pmf(i, n-1, 2, 2)
722-
x = 0.6 * np.random.uniform(-1.5, 1.5)
723-
y = 0.6 * np.random.uniform(-1.5, 1.5)
723+
x = 0.6 * rng.uniform(-1.5, 1.5)
724+
y = 0.6 * rng.uniform(-1.5, 1.5)
724725
725726
name = group + str(i)
726727
nodes.append(Node(x, y, m, group, name))

0 commit comments

Comments
 (0)