{"action":"created","issue":{"url":"https://api.github.com/repos/networkx/networkx/issues/1764","repository_url":"https://api.github.com/repos/networkx/networkx","labels_url":"https://api.github.com/repos/networkx/networkx/issues/1764/labels{/name}","comments_url":"https://api.github.com/repos/networkx/networkx/issues/1764/comments","events_url":"https://api.github.com/repos/networkx/networkx/issues/1764/events","html_url":"https://github.com/networkx/networkx/issues/1764","id":105195170,"number":1764,"title":"Graph generators change default random seed","user":{"login":"AgostinoSturaro","id":1441393,"avatar_url":"https://avatars.githubusercontent.com/u/1441393?v=3","gravatar_id":"","url":"https://api.github.com/users/AgostinoSturaro","html_url":"https://github.com/AgostinoSturaro","followers_url":"https://api.github.com/users/AgostinoSturaro/followers","following_url":"https://api.github.com/users/AgostinoSturaro/following{/other_user}","gists_url":"https://api.github.com/users/AgostinoSturaro/gists{/gist_id}","starred_url":"https://api.github.com/users/AgostinoSturaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AgostinoSturaro/subscriptions","organizations_url":"https://api.github.com/users/AgostinoSturaro/orgs","repos_url":"https://api.github.com/users/AgostinoSturaro/repos","events_url":"https://api.github.com/users/AgostinoSturaro/events{/privacy}","received_events_url":"https://api.github.com/users/AgostinoSturaro/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/networkx/networkx/labels/Enhancement","name":"Enhancement","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/networkx/networkx/milestones/3","html_url":"https://github.com/networkx/networkx/milestones/networkx-2.0","labels_url":"https://api.github.com/repos/networkx/networkx/milestones/3/labels","id":236124,"number":3,"title":"networkx-2.0","description":"","creator":{"login":"hagberg","id":187875,"avatar_url":"https://avatars.githubusercontent.com/u/187875?v=3","gravatar_id":"","url":"https://api.github.com/users/hagberg","html_url":"https://github.com/hagberg","followers_url":"https://api.github.com/users/hagberg/followers","following_url":"https://api.github.com/users/hagberg/following{/other_user}","gists_url":"https://api.github.com/users/hagberg/gists{/gist_id}","starred_url":"https://api.github.com/users/hagberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hagberg/subscriptions","organizations_url":"https://api.github.com/users/hagberg/orgs","repos_url":"https://api.github.com/users/hagberg/repos","events_url":"https://api.github.com/users/hagberg/events{/privacy}","received_events_url":"https://api.github.com/users/hagberg/received_events","type":"User","site_admin":false},"open_issues":107,"closed_issues":135,"state":"open","created_at":"2012-12-29T15:43:08Z","updated_at":"2016-02-11T13:37:24Z","due_on":"2016-03-15T06:00:00Z","closed_at":null},"comments":9,"created_at":"2015-09-07T11:00:14Z","updated_at":"2016-02-12T21:10:54Z","closed_at":null,"body":"I noticed that, when passing graph generators a `seed` parameter, they change the *default* seed for `random`. This affects affecting all subsequent calls to `random` in the module.\r\nThat is, if a single generator is passed a `seed` parameter, all other generators are affected.\r\n[Most](https://github.com/networkx/networkx/blob/v1.10/networkx/generators/random_graphs.py#L47) [generators](https://github.com/networkx/networkx/blob/v1.10/networkx/generators/random_graphs.py#L602) seem to be doing this. The code in question is\r\n\r\n    if seed is not None:\r\n        random.seed(seed)\r\n\r\nHere's a discussion [on SO](http://stackoverflow.com/q/12368996/1600770). There is a simple solution. Creating an instance of `random` inside each function would make the seed change self-contained and prevent it from affecting other calls. Something like this would do\r\n\r\n    if seed is not None:\r\n        my_random = random.Random(seed)\r\n    else:\r\n        my_random = random\r\n    ...\r\n    # use my_random for calls\r\n\r\nThe same trick can be used if a NumPy random generator is needed\r\n\r\n    my_random = np.random.RandomState(seed)\r\n\r\nThis could be especially useful to add a `seed` parameter to the layout functions, that currently lack one, and do not provide a way to arrange nodes deterministically (the same way in two different calls). see for instance [this function](https://github.com/networkx/networkx/blob/v1.9.1/networkx/drawing/layout.py#L55).\r\n"},"comment":{"url":"https://api.github.com/repos/networkx/networkx/issues/comments/183489413","html_url":"https://github.com/networkx/networkx/issues/1764#issuecomment-183489413","issue_url":"https://api.github.com/repos/networkx/networkx/issues/1764","id":183489413,"user":{"login":"NeilGirdhar","id":730137,"avatar_url":"https://avatars.githubusercontent.com/u/730137?v=3","gravatar_id":"","url":"https://api.github.com/users/NeilGirdhar","html_url":"https://github.com/NeilGirdhar","followers_url":"https://api.github.com/users/NeilGirdhar/followers","following_url":"https://api.github.com/users/NeilGirdhar/following{/other_user}","gists_url":"https://api.github.com/users/NeilGirdhar/gists{/gist_id}","starred_url":"https://api.github.com/users/NeilGirdhar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NeilGirdhar/subscriptions","organizations_url":"https://api.github.com/users/NeilGirdhar/orgs","repos_url":"https://api.github.com/users/NeilGirdhar/repos","events_url":"https://api.github.com/users/NeilGirdhar/events{/privacy}","received_events_url":"https://api.github.com/users/NeilGirdhar/received_events","type":"User","site_admin":false},"created_at":"2016-02-12T21:10:54Z","updated_at":"2016-02-12T21:10:54Z","body":"@jeffzemla It is one extra indirection without value.\r\n\r\nIf you want a magic number in your code (why you want that I have no idea), you can still do: `rng=RandomState(1234)`.\r\n\r\nIf I've ever had a fixed seed, it was usually in exactly one place in the code, rather than mixed in everywhere."}}