Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

How to generate random string from specific pattern?

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

How to generate random string from specific pattern?

#1 Post by hack3rcon »

Hello.
How can I generate random string from a specific pattern? For example, My pattern is "Hey, Hello World!" and I want generate it randomly. Something like:

Code: Select all

Hello World! Hey, Hello, Hey World!
Thanks.

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 503
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: How to generate random string from specific pattern?

#2 Post by Bloom »

Not exactly random, but perhaps this helps?

Code: Select all

echo "Hey, Hello World!" | tr ' ' '\n' | shuf | tr '\n' ' '

hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

Re: How to generate random string from specific pattern?

#3 Post by hack3rcon »

Bloom wrote:Not exactly random, but perhaps this helps?

Code: Select all

echo "Hey, Hello World!" | tr ' ' '\n' | shuf | tr '\n' ' '
Thanks.
How can I generate it to a certain number?

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 503
Joined: 2017-11-11 12:23
Been thanked: 26 times

Re: How to generate random string from specific pattern?

#4 Post by Bloom »

This will shuffle the words in the sentence you specify, so the total length will always be the same.
The following code will give you actual random alphanumeric characters en here you can specify the length:

Code: Select all

strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 8 | tr -d '\n'; echo;
This will yield a 8 character response. If you want a different number, just replace the 8 with the number wanted.

Post Reply