![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
[C++] Pseudo-random "password" generator
I got bored and made a simple programme that generates a pseudo-random string containing lower and uppercase letters and digits.
Surprisingly enough, I actually have use for this program... Odd. #include <iostream>
#include <time.h>
int main(void){
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
unsigned int i,j;
start:
std::cout<<"Enter amount of chars (max 16386): ";
std::cin>>j;
if (j>16386)
{
std::cout<<"error: too much\n";
goto start;
}
for (i=0;i<1;++i)
{
unsigned int a[j];
for (i=0;i<j;++i)
{
while (!(((a[i]=rand())>='0'&&a[i]<='9')||(a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z')))
;
printf("%c",a);
}
}
printf("\n");
std::cout << "Press enter to continue...";
std::cin.sync();
std::cin.get();
std::cout << std::endl;
goto start;
}I know, I know. I used gotos... but I sort of like them! ![]() Edit: Also, I have no idea why I put a redundant for loop there. ![]() Edit again: Oh, right! To make a new array every time it loops! Though I could've just reset it... Oh well ![]() |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Agh, what is that while line! That could theoretically pop it into a almost infinite loop ... a kill on processing time. The rest of the code looks pretty dirty, and GOTOs are evil, but i congratulate you on a working program since that was probably your primary goal at your skill level. Good job, but LOTS to work on
![]()
__________________
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
I guess I like working quickly and dirty
![]() I'll get back to it some time though. Edit: In that while loop, the forum decided to format my code's [ i ] as vBcode and instead of putting the [ i ] there, it put the code that followed in Italic, so it's always evaluating a[0]. I didn't notice what the problem was at the time, so I just added a [/ i ] at the end of the code block. Oh, well. ![]() |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
add a [i] to the top of the code block next time and it'll be set, it seems like it only processes the first one since doing the rest would be redundant (although the entire prospect of BBCode in the [ code ] tag is stupid in the first place...)
__________________
|
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
But a[i] is fairly common in C code as well.
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() |
well, i mean for code it's important to give the user the ability to turn the feature on and off atleast ... or even if they didn't want to do that, they could limit the tags possible to use to like [ highlight ] or something....
__________________
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
Yesh. Or implement something like:
tags Syntax (Toggle Plain Text)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|