{"action":"created","issue":{"url":"https://api.github.com/repos/pytoolz/toolz/issues/299","repository_url":"https://api.github.com/repos/pytoolz/toolz","labels_url":"https://api.github.com/repos/pytoolz/toolz/issues/299/labels{/name}","comments_url":"https://api.github.com/repos/pytoolz/toolz/issues/299/comments","events_url":"https://api.github.com/repos/pytoolz/toolz/issues/299/events","html_url":"https://github.com/pytoolz/toolz/issues/299","id":147167535,"number":299,"title":"Would like to add `random-sample`","user":{"login":"steven-cutting","id":8365892,"avatar_url":"https://avatars.githubusercontent.com/u/8365892?v=3","gravatar_id":"","url":"https://api.github.com/users/steven-cutting","html_url":"https://github.com/steven-cutting","followers_url":"https://api.github.com/users/steven-cutting/followers","following_url":"https://api.github.com/users/steven-cutting/following{/other_user}","gists_url":"https://api.github.com/users/steven-cutting/gists{/gist_id}","starred_url":"https://api.github.com/users/steven-cutting/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/steven-cutting/subscriptions","organizations_url":"https://api.github.com/users/steven-cutting/orgs","repos_url":"https://api.github.com/users/steven-cutting/repos","events_url":"https://api.github.com/users/steven-cutting/events{/privacy}","received_events_url":"https://api.github.com/users/steven-cutting/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-09T22:01:38Z","updated_at":"2016-04-09T22:12:30Z","closed_at":null,"body":"I would like to contribute a simple lazy random sampling method, that is (basically) identical to Clojure's `random-sample`.\r\n\r\nPython's library `random` has a sample function but, it is not lazy.\r\n\r\n```python\r\nfrom random import random\r\nfrom toolz import filter\r\n\r\ndef random_sample(prob, col):\r\n    return filter(lambda _: random() < prob, col)\r\n```\r\n\r\nCode for Clojure's `random-sample`\r\n```clojure\r\n(defn random-sample\r\n  \"Returns items from coll with random probability of prob (0.0 -\r\n  1.0).  Returns a transducer when no collection is provided.\"\r\n  {:added \"1.7\"}\r\n  ([prob]\r\n     (filter (fn [_] (< (rand) prob))))\r\n  ([prob coll]\r\n     (filter (fn [_] (< (rand) prob)) coll)))\r\n```\r\n\r\nI'll go ahead and wright it up and submit a pull request if that's ok?\r\nI don't have experience with cython, so I'm not sure if I will be able to write a version for cytoolz."},"comment":{"url":"https://api.github.com/repos/pytoolz/toolz/issues/comments/207865081","html_url":"https://github.com/pytoolz/toolz/issues/299#issuecomment-207865081","issue_url":"https://api.github.com/repos/pytoolz/toolz/issues/299","id":207865081,"user":{"login":"llllllllll","id":3064397,"avatar_url":"https://avatars.githubusercontent.com/u/3064397?v=3","gravatar_id":"","url":"https://api.github.com/users/llllllllll","html_url":"https://github.com/llllllllll","followers_url":"https://api.github.com/users/llllllllll/followers","following_url":"https://api.github.com/users/llllllllll/following{/other_user}","gists_url":"https://api.github.com/users/llllllllll/gists{/gist_id}","starred_url":"https://api.github.com/users/llllllllll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/llllllllll/subscriptions","organizations_url":"https://api.github.com/users/llllllllll/orgs","repos_url":"https://api.github.com/users/llllllllll/repos","events_url":"https://api.github.com/users/llllllllll/events{/privacy}","received_events_url":"https://api.github.com/users/llllllllll/received_events","type":"User","site_admin":false},"created_at":"2016-04-09T22:12:30Z","updated_at":"2016-04-09T22:12:30Z","body":"This function breaks the purity presented by toolz. I am -0.5 because I think it will make it harder to write reproducible code, but I could see a version that accepts a `random.Random` to use instead just calling `random()`"}}