Timeline for Tips for golfing in Python
Current License: CC BY-SA 2.5
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 5, 2023 at 13:35 | comment | added | Joao-3 | If you want to generate random bytes, of course. | |
| Jul 5, 2018 at 9:41 | comment | added | user202729 | @Fraxtil id can be applied on mostly everything, such as 1 or []. | |
| Apr 20, 2013 at 2:04 | comment | added | ashastral | Late to the party, but if you only need a few random numbers, try using id(id), substituting the inner id with any 3-letter builtin if you need more than one. 'abc'[id(id)%3] is 11 characters shorter than 'abc'[random.randrange(3)], not even counting the import statement. | |
| May 1, 2011 at 7:17 | comment | added | gnibbler | @Josh, don't forget you need to import random vs import os. randint() needs 3 parameters anyway. If you need a list of random numbers, you can use map(ord,os.urandom(N)) Also, sometimes, you actually need a random char instead of a number | |
| May 1, 2011 at 3:10 | comment | added | jscs | Doesn't this require use of ord() to get a number instead of character? len("ord(os.urandom(1))") -> 18 and len("random.randint()") -> 16 | |
| Feb 3, 2011 at 20:32 | history | answered | gnibbler | CC BY-SA 2.5 |