{"action":"created","issue":{"url":"https://api.github.com/repos/aysylu/loom/issues/51","labels_url":"https://api.github.com/repos/aysylu/loom/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/aysylu/loom/issues/51/comments","events_url":"https://api.github.com/repos/aysylu/loom/issues/51/events","html_url":"https://github.com/aysylu/loom/issues/51","id":58636957,"number":51,"title":"gen-rand throws exception for weighted graphs unless min-weight and max-weight are explicitly provided","user":{"login":"tihancock","id":1465707,"avatar_url":"https://avatars.githubusercontent.com/u/1465707?v=3","gravatar_id":"","url":"https://api.github.com/users/tihancock","html_url":"https://github.com/tihancock","followers_url":"https://api.github.com/users/tihancock/followers","following_url":"https://api.github.com/users/tihancock/following{/other_user}","gists_url":"https://api.github.com/users/tihancock/gists{/gist_id}","starred_url":"https://api.github.com/users/tihancock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tihancock/subscriptions","organizations_url":"https://api.github.com/users/tihancock/orgs","repos_url":"https://api.github.com/users/tihancock/repos","events_url":"https://api.github.com/users/tihancock/events{/privacy}","received_events_url":"https://api.github.com/users/tihancock/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-23T19:40:53Z","updated_at":"2015-03-08T01:38:02Z","closed_at":null,"body":"This is due to https://github.com/aysylu/loom/blob/master/src/loom/gen.clj#L15 where Random.nextInt is called with 0 if the default min-weight and max-weight are used.\r\n\r\nI can see a few ways to avoid this exception:\r\n1. A pre-condition asserting `(if (weighted? g) (< min-weight max-weight))`\r\n2. Setting the default weights to some other sensible values (1 and 100?)\r\n3. Changing rand-w to \r\n```#(if (< min-weight max-weight)\r\n          (+ (.nextInt rnd (- max-weight min-weight)) min-weight)\r\n          min-weight)```\r\n\r\nOf the three I think I like some variation of the third best. I'm happy to put together a pull request if you think this is a good change."},"comment":{"url":"https://api.github.com/repos/aysylu/loom/issues/comments/77727296","html_url":"https://github.com/aysylu/loom/issues/51#issuecomment-77727296","issue_url":"https://api.github.com/repos/aysylu/loom/issues/51","id":77727296,"user":{"login":"aysylu","id":619994,"avatar_url":"https://avatars.githubusercontent.com/u/619994?v=3","gravatar_id":"","url":"https://api.github.com/users/aysylu","html_url":"https://github.com/aysylu","followers_url":"https://api.github.com/users/aysylu/followers","following_url":"https://api.github.com/users/aysylu/following{/other_user}","gists_url":"https://api.github.com/users/aysylu/gists{/gist_id}","starred_url":"https://api.github.com/users/aysylu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aysylu/subscriptions","organizations_url":"https://api.github.com/users/aysylu/orgs","repos_url":"https://api.github.com/users/aysylu/repos","events_url":"https://api.github.com/users/aysylu/events{/privacy}","received_events_url":"https://api.github.com/users/aysylu/received_events","type":"User","site_admin":false},"created_at":"2015-03-08T01:38:02Z","updated_at":"2015-03-08T01:38:02Z","body":"Thanks for catching this! I like the 1st option best because it makes it explicit what the preconditions are for the function to work correctly. I'd be happy to accept your PR if you're interested."}}