Skip to main content
Share Your Experience: Take the 2024 Developer Survey
55 votes

Random IP Address Generator

Python is often described as a "batteries included" kind of language, and this is no exception. There's a module just for IP address manipulation and another module to generate random numbers. Put ...
emmalyx's user avatar
  • 619
38 votes
Accepted

Random password generator in C

I see some things that I think could help you improve your code. Decompose your program into functions All of the logic here is in main in one rather long and ...
Edward's user avatar
  • 66.4k
36 votes
Accepted

20 Ways to do Random Sampling

It would be worth your while to take a look at the implementation of random.sample to see how it works. (It's different from all 20 implementations in the post, and ...
Gareth Rees's user avatar
  • 49.6k
30 votes
Accepted

6 out of 49 Lottery

Bug Winning a 6/49 game is, of course, unlikely. The probability of any single ticket having all six numbers correct is $$\dfrac{1}{\binom{49}{6}} = \dfrac{6!\,(49-6)!}{49!} = \dfrac{1}{13983816}$$ ...
200_success's user avatar
29 votes

Generate a list of 10,000 numbers in random order

In general First and foremost, you were asked to produce a program that generates a list of 10,000 numbers in random orders. You've added far too much complexity. There's no need for input or output (...
Rob's user avatar
  • 652
28 votes
Accepted

C++ Coin flip simulator and data collector

There's a lot that can be improved here, so I hope that these suggestions are useful to you. Don't abuse using namespace std Putting ...
Edward's user avatar
  • 66.4k
26 votes

Random IP Address Generator

Here are a few ideas about your code. Check for command line arguments The code fails with an exception if it's invoked with no command line arguments because it attempts to use ...
Edward's user avatar
  • 66.4k
24 votes

Random alphanumeric password generator with GOTOs

Data structure Why are you using a LinkedList<char>? Linked lists involve a lot of overhead for each node. You know exactly how long the result should be, ...
200_success's user avatar
24 votes

Laughably tiny random engine

Your question has two parts: Is the algorithm good? Is the implementation good? The first part is not really the purview of code review, because it is not only a mathematical question, it is an ...
indi's user avatar
  • 11.4k
23 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 ...
Reinderien's user avatar
  • 62.1k
21 votes
Accepted

Python \ random password generation code

Don't use random for security Quoting from the documentation for random: Warning: The pseudo-random generators of this module ...
gazoh's user avatar
  • 3,269
20 votes

Python program to scramble MP3 audio

Consider what happens if a user closes the "Load MP3" dialog without picking a file. In that case, filepath would get set to ...
Sara J's user avatar
  • 3,442
19 votes

Random IP Address Generator

For someone not familiar with Python, you have picked pretty good habits. Not everyone uses functions or the if __name__ == '__main__' guard first try. That being ...
301_Moved_Permanently's user avatar
18 votes
Accepted

Solving for Bananas

General Feedback The good thing is that it is quite clear what your code does. You have for the most part clear variable names and not too much clutter. However I would change ...
N3buchadnezzar's user avatar
18 votes

Create two random teams from a list of players

Review Don't use the main entry point to implement an algorithm. Create a method instead. Think about how to allow this method to be usable for all kinds of types, not just integers. You have ...
dfhwze's user avatar
  • 13.9k
17 votes

20 Ways to do Random Sampling

You should not use eval without a very good reason. This is not a very good reason. Even though here you are actually fully in control of what gets passed to ...
Graipher's user avatar
  • 41k
17 votes
Accepted

Generate 10 random 3-letter strings

Python 3.6 introduced random.choices, which allows you to write this even more succinctly than using random.choice: ...
Graipher's user avatar
  • 41k
17 votes

A dice game called "Greed"

Style You're not being charged by the character; there's no need to abbreviate "count", or "ret" (which I would call "score" instead). Also, main has inconsistent brackets with the rest of the ...
Errorsatz's user avatar
  • 1,354
17 votes
Accepted

Laughably tiny random engine

Possibility of short cycles SHA256 is a cryptographically secure hash function, which indeed means the output is very uncorrelated to the input. However, given exactly the same input, it will always ...
G. Sliepen's user avatar
  • 57.2k
17 votes
Accepted

Python command-line program that generates passwords

Put all code in functions. Code in functions can be tested, experimented with, and reorganized much more easily than code floating around at the top level. Floating code introduces the temptation to ...
FMc's user avatar
  • 12.7k
16 votes
Accepted

Random string of variable length generator

Just two remarks: RandomChar should be a method because it returns a different result each time - this is just a convention that we usually follow in C# In ...
t3chb0t's user avatar
  • 44.3k
16 votes

Python program to scramble MP3 audio

There is quite some room for improvement, both in the overall architecture and style and in the logic that you use: Architecture and style Separate logic from presentation You have a single class ...
gazoh's user avatar
  • 3,269
15 votes
Accepted

Pick a random big word from a list of words using Python

Comments Python functions are written in snake_case. You could use function parameters for word length and filename. You could use iterators and generators to ...
Eric Duminil's user avatar
  • 3,950
15 votes

20 Ways to do Random Sampling

Besides the good points of @Graipher's answer: Examples n° 6, 7, 10, 11, 12, 14, 15, 16, and 20 are the only one that modify the input data and thus only them need to copy the input to not modify it. ...
301_Moved_Permanently's user avatar
15 votes

Markov chains to generate text

Functions Split the code into functions, also split the generation and the presentation. Your algorithm has some clear distinct tasks, so split along these lines: read input assemble chain construct ...
Maarten Fabré's user avatar
15 votes
Accepted

Generating a unique key

You can pass str to map rather than a lambda. You can remove the need for ...
Peilonrayz's user avatar
  • 43.4k
14 votes
Accepted

C++ Random Phone Number Generator

Here are some observations that may help you improve your code. Don't abuse using namespace std Putting using namespace std at ...
Edward's user avatar
  • 66.4k
14 votes

Random IP Address Generator

Check for invalid outputs, and regenerate them. It's possible that you'll produce an output that's reserved for a particular purpose, such as loopback (127.0.0.1 or ...
Toby Speight's user avatar
14 votes

Random password generator in C

There is a bug in this line: password[i] = symbols[rand() % 26]; symbols is only 21 characters long, so this line triggers ...
trent's user avatar
  • 1,064

Only top scored, non community-wiki answers of a minimum length are eligible