Timeline for Generate 10 random 3-letter strings
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 10, 2018 at 12:23 | history | edited | esote | CC BY-SA 4.0 |
added 6 characters in body
|
Jul 10, 2018 at 11:59 | comment | added | Graipher |
Wow, it is actually faster: %timeit [0 for _ in range(10000000)] : 325 ms ± 1.38 ms, %timeit [0 for _ in repeat(None, 10000000)] : 184 ms ± 1.72 ms. That's a factor 2! (Of course this is only relevant as long as looping dominates the timing and not the execution of the function itself.)
|
|
Jul 10, 2018 at 11:48 | history | edited | esote | CC BY-SA 4.0 |
Use secrets module
|
Jul 10, 2018 at 11:35 | comment | added | esote |
@IzaakvanDongen thanks for your feedback, I've edited my answer to include your suggestions (and fixed itrertools.repeat , I'd forgotten that it returns the same thing N times, instead of calling it N times).
|
|
Jul 10, 2018 at 11:34 | history | edited | esote | CC BY-SA 4.0 |
Fixes
|
Jul 10, 2018 at 9:51 | comment | added | Izaak van Dongen |
You should probably only be using one SystemRandom instance. Also, if you're extend ing an empty list with a generator expression you might as well just use a list comprehension. Lastly, your use of itertools.repeat just produces the same string 10 times - this may be random in the XKCD sense but probably isn't what OP was after.
|
|
Jul 10, 2018 at 2:14 | history | edited | esote | CC BY-SA 4.0 |
Properly use itertools.repeat
|
Jul 10, 2018 at 2:02 | history | edited | esote | CC BY-SA 4.0 |
Use extend
|
Jul 10, 2018 at 1:55 | history | edited | esote | CC BY-SA 4.0 |
Use array
|
Jul 10, 2018 at 1:44 | history | answered | esote | CC BY-SA 4.0 |