2022 Developer Survey is open! Take survey.

New answers tagged

1 vote

Randomized Queue with ArrayList from Princeton's Algorithm Book

It's not a good idea to use an ArrayList because the object of the class is to teach you algorithms and data structures, so when you submit the assignment, the tests will fail, because ...
user avatar
  • 111
1 vote

Sampling from k circles with different radii

I don't have much to add to the answer of @Reinderien, maybe a slightly different solution. ...
user avatar
  • 1,339
3 votes

Sampling from k circles with different radii

Let's assume that your zip-shortest behaviour is intended. radii and centers should immediately be made ...
user avatar
  • 47.9k
2 votes
Accepted

Generating random integers in one of three ranges

An issue I see with this code is that it behaves unexpectedly if passed another value than 1, 2 or ...
user avatar
  • 1,215
1 vote

Generating random integers in one of three ranges

>>> 10**1 10 >>> 10**2 100 >>> 10**3 1000 So you can do randrange(10**(level - 1), 10**level) for a ...
user avatar
  • 8,717
2 votes

Simple Python code that makes a random string of letters and numbers

The current answers capture pretty much everything, but here's an alternative approach if you would be interested. If you don't want to rely on an import for your ascii list, but still want to be sure ...
user avatar
  • 129
2 votes

Simple Python code that makes a random string of letters and numbers

Since strings are iterables, you can do this one liner: ...
user avatar
  • 21
3 votes

Simple Python code that makes a random string of letters and numbers

I feel like the code can be made shorter. I just don't know how. If you want your code to be shorter, you could use a single list, like this. ...
user avatar
  • 31
0 votes

Cryptographically secure version of the core array_rand() function

This is not API compatible with array_rand, as it doesn't have the ability to return more than one key (but array_rand does). ...
user avatar
  • 20.3k
22 votes
Accepted

Simple Python code that makes a random string of letters and numbers

Don't use caps, numbers and letters; those are all constants available from the ...
user avatar
  • 47.9k
3 votes

Simple Python code that makes a random string of letters and numbers

Disclaimer: I'm note 100% sure that your code does what you think it does. Anyway, various things can be improved in the code without changing the behavior. Style There is a Python style guide called ...
user avatar
  • 28.7k

Top 50 recent answers are included