File tree Expand file tree Collapse file tree 2 files changed +72
-32
lines changed Expand file tree Collapse file tree 2 files changed +72
-32
lines changed Original file line number Diff line number Diff line change 16
16
"outputs" : [],
17
17
"source" : [
18
18
" import igraph as ig\n " ,
19
+ " import random\n " ,
20
+ " from contextlib import contextmanager\n " ,
19
21
" ig.config[\" plotting.backend\" ] = \" matplotlib\" "
20
22
]
21
23
},
24
+ {
25
+ "cell_type" : " code" ,
26
+ "execution_count" : null ,
27
+ "id" : " d2d768d4-a5d4-4c72-b044-25ea095a7c0d" ,
28
+ "metadata" : {},
29
+ "outputs" : [],
30
+ "source" : [
31
+ " @contextmanager\n " ,
32
+ " def local_random(seed=None):\n " ,
33
+ " \"\"\" Temporarily set the random state, restoring it afterwards.\"\"\"\n " ,
34
+ " state = random.getstate()\n " ,
35
+ " if seed is not None:\n " ,
36
+ " random.seed(seed)\n " ,
37
+ " try:\n " ,
38
+ " yield\n " ,
39
+ " finally:\n " ,
40
+ " random.setstate(state)"
41
+ ]
42
+ },
22
43
{
23
44
"cell_type" : " code" ,
24
45
"execution_count" : 2 ,
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments