Generating random characters in console; Ctrl + C doesn't stop the command

Post Reply
Message
Author
THX11384EB
Posts: 6
Joined: Wed Apr 17, 2019 2:34 pm

Generating random characters in console; Ctrl + C doesn't stop the command

#1 Post by THX11384EB »

I'm trying to generate some random characters for a thing and I'm using console commands I found on the Internet. I've encountered a behaviour that was unexpected and I wanted to find out whether it was a bug.

If I use the command:

Code: Select all

</dev/urandom tr -dc A-Za-z0-9\!£%$ | head -c 26 ; echo
then I get 26 characters as expected. If I use the following command then the random characters just keep scrolling past and pressing Ctrl + C does not stop the mayhem.

Code: Select all

</dev/urandom tr -dc A-Za-z0-9\!£%$^&*~#:;? | head -c 26 ; echo
Why does this happen?

I'm using Antix 17.04.

User avatar
BitJam
Developer
Posts: 2283
Joined: Sat Aug 22, 2009 11:36 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#2 Post by BitJam »

That code is horrid in a number of ways. Please try this instead:

Code: Select all

dd if=/dev/urandom bs=13 count=1 status=none | od -An -x | tr -d " \n"
It will give you a string of 26 random hex characters.
"The first principle is that you must not fool yourself -- and you are the easiest person to fool."

-- Richard Feynman

THX11384EB
Posts: 6
Joined: Wed Apr 17, 2019 2:34 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#3 Post by THX11384EB »

Thanks. How do I get it to include special characters?

THX11384EB
Posts: 6
Joined: Wed Apr 17, 2019 2:34 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#4 Post by THX11384EB »

Can anyone advise me on how to get this command to include special characters (e.g. £, $, %, ^, &, *, [, @, # etc)?

If possible, I'd like five rows of 26 random characters including special characters but I can also just manually arrange them into five rows of 26. Thanks.

User avatar
Head_on_a_Stick
Posts: 919
Joined: Sun Mar 17, 2019 3:37 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#5 Post by Head_on_a_Stick »

Code: Select all

pwgen -sy -1 26 5
mod note: Signature removed, please read the forum rules

THX11384EB
Posts: 6
Joined: Wed Apr 17, 2019 2:34 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#6 Post by THX11384EB »

Thanks but the pwgen command is not recognised.

User avatar
Head_on_a_Stick
Posts: 919
Joined: Sun Mar 17, 2019 3:37 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#7 Post by Head_on_a_Stick »

Code: Select all

sudo apt install pwgen
mod note: Signature removed, please read the forum rules

User avatar
ChrisUK
Qualified MX Guide
Posts: 299
Joined: Tue Dec 12, 2017 1:04 pm

Re: Generating random characters in console; Ctrl + C doesn't stop the command

#8 Post by ChrisUK »

Not what you asked, but:

There's many different ways of generating passwords in the Terminal, but one that doesn't (IMO) get enough of a mention is Diceware... gives you easy(ish) to remember (and strong?) passwords without meaningless characters.

EDIT: oops... wrong url ;)

Here's the correct one.
Chris

MX 18 MX 19 - Manjaro

Post Reply

Return to “antiX”