Passcode generator
EitanKhiyaev (6)

I only got 2 months of coding experience. just decided to build this simple project. this is something simple i decided to put together, is there anything i could improve on?

You are viewing a single comment. View All
Highwayman (1340)

Awesome use of the switch statement but you forgot to put a break on line 32.
Also you can use the <random> Header for random number generation. You can still seed it with time(0) though so that’s not too bad. Here’s a. Tutorial I made on it recently it’s really easy and fast: https://repl.it/talk/learn/Random-Number-Generation-in-C/24953

Highwayman (1340)

@EitanKhiyaev your welcome, Also don’t use sizeof() to test the size of an array, it doesn’t always work.

[deleted]

@Highwayman sizeof on an array doesn't do what you think it would do

Highwayman (1340)

@sanjaykdragon yes it is, and for this it will work, but it is a bad practice, because I’ve see people get to comfy with it and try and use sizeof with a pointer and that doesn’t work. So. My statement still stands.

[deleted]

@Highwayman sizeof an array does not return the length of an array. You are looking for .size() (C++17 arrays)

Highwayman (1340)

@sanjaykdragon 🤦‍♂️ I think you need to read my comment again because you’re assuming a lot of stupid where there isn’t, I’m honestly kind of insulted. I know what sizeof does, what it does has certain side affects that are sometimes exploited to the detriment of those of us still learning. Also it’s a C style array. Not a fancy aggregate type. There is not special function member in the array. It’s just. an array. next time read more carefully because nowhere in my post do I even try to explain what it does, because it doesn’t matter because I’m telling them not to use it.

[deleted]

@Highwayman Next time read the post I made above before you spew misinformation. I told OP to use std::array instead.

Highwayman (1340)

@sanjaykdragon you weren’t talking to the OP., you were talking to me, and I was discussing regular c arrays, your post to the OP is irrelevant unless mentioned to me as you have done. I do agree though that an stl container would be better.

[deleted]

@Highwayman read the separate comment I made

Highwayman (1340)

@sanjaykdragon what? Which one? Also sorry about yesterday, you just accidentally hit a nerve with me and I just got too angry too fast sorry about that.

[deleted]

@Highwayman its in a separate comment thread (same post, just not in this comment chain)

Highwayman (1340)

@sanjaykdragon oh, do you mean the one you mentioned earlier about using the stl array container?

[deleted]

@Highwayman STL array is way better than the default array

Highwayman (1340)

@sanjaykdragon you could say that. Not necessarily though. A full template for just a different size is kind of excessive. Vector works just as well, If were really this lazy.

[deleted]

@Highwayman vector is used for different reasons, and has different performance than arrays (worse in this context im pretty sure)

Highwayman (1340)

@sanjaykdragon meh. Not for indexing I’m sure. Probably for creation though