Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Here is a task... Find Nothing :P

random bash loop number golden

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 ShaunPrawn

ShaunPrawn

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 07 August 2014 - 06:09 AM

Hello!

 

Nice forum.

 

What does everyone think of this ??

Being a little devilish, I forgot comments..

#!/bin/bash
# Author: Shaun Pearce <shaun-p@mweb.co.za>
# Date: July 28th 2014
# Usage: <cmd>
# Misc: creates 12 files.. 4 history and 8 i/o
# Credit: The Matrix by Antek Sawicki <tenox@tenox.tc> 
#
#>>>>>>>> What does it do <<<<<<<<#
#				  #
#	A random bit generator    #
#	spits out characters to   #
#	a test loop which finds   #
#	identical hits..          #
#	Stores hits and number    #
#	of iterations of 2, 3,    #
#	4 and 5 characters.	  #
#				  			#
#	Therefore testing the     #
#	randomness of $RANDOM. 
#	I think.   			#
#				  			#
###############################
BIT=( 2 3 4 5 )			        
if [ ! -e 42.hist ]; then
	for b in "${BIT[@]}";do
		touch 4"$b".hist	
	done
fi
_MATRIX () { 				
	for m in "${BIT[@]}";do
MATRIX="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
		LENGTH="$m"
		while [ "${n:=1}" -le "$LENGTH" ];do
		    PASS="$PASS ${MATRIX:$(($RANDOM%${#MATRIX})):1}"
			let n+=1
			done
	echo "$PASS">pass."$m"
	n= 
	PASS=
	done 
}
_BIT () { 
	for i in "${BIT[@]}";do
		cat "pass.$i" | \
awk '{ print $1, $2, $3, $4, $5 }'>"$i".f;done
}							
_READ () { 
	for c in "${BIT[@]}";do			
		eval CODE=(`cat "$c".f`)	
		if [ "$c" -eq "2" ]; then	
					A=${CODE[0]}		
					B=${CODE[1]}
		elif [ "$c" -eq "3" ];then
					C=${CODE[0]}
					D=${CODE[1]}
					E=${CODE[2]}
		elif [ "$c" -eq "4" ];then
					F=${CODE[0]}
					G=${CODE[1]}
					H=${CODE[2]}
					I=${CODE[3]}
		elif [ "$c" -eq "5" ];then
					J=${CODE[0]}
					K=${CODE[1]}
					L=${CODE[2]}
					M=${CODE[3]}
					N=${CODE[4]}
			fi
		done							
}
_TEST () { 
for o in "${BIT[@]}";do
	if [ $o -eq 2 ];then	#########
	((COUNT2 +=1))
	if [ "$A" -le "9" ] &>/dev/null;then   
	        if [ "$A" -eq "$B" ] >& /dev/null;then
		    echo "$A $B" $COUNT2>>42.hist;COUNT2=0
		    fi
		elif [ "$A" = "$B" ] >& /dev/null;then
		    echo "$A $B" $COUNT2>>42.hist;COUNT2=0
		    fi				
	elif [ "$o" -eq "3" ];then 	#########
	((COUNT3 +=1))
	if [ "$C" -le "9" ] &>/dev/null;then
		if [ "$C" -eq "$D" -a "$E" -eq "$C" ] &>/dev/null;then
			echo "$C $D $E" $COUNT3>>43.hist;COUNT3=0
			fi
		elif [ "$C" = "$D" -a "$E" = "$C" ] &>/dev/null;then
			echo "$C $D $E" $COUNT3>>43.hist;COUNT3=0
			fi	
	elif [ "$o" -eq "4" ];then	#########
	((COUNT4 +=1))
	if [ "$F" -le "9" ] &>/dev/null;then
		if [ "$F" -eq "$G" -a "$H" -eq "$F" \
			-a "$I" -eq "$F" ] &>/dev/null;then
			echo "$F $G $H $I" $COUNT4>>44.hist;COUNT4=0
			fi
		elif [ "$F" = "$G" -a "$H" = "$F" \
			-a "$I" = "$F" ] &>/dev/null;then
			echo "$F $G $H $I" $COUNT4>>44.hist;COUNT4=0
			fi			
	elif [ "$o" -eq "5" ];then	#########
        ((COUNT5 +=1))
  	 if [ "$J" -le "9" ] &>/dev/null;then
		if [ "$J" -eq "$K" -a "$L" -eq "$J" \
			-a "$M" -eq "$J" -a "$N" -eq "$J" ] &>/dev/null;then
			echo "$J $K $L $M $N" $COUNT5>>45.hist;COUNT5=0
			fi
		elif [ "$J" = "$K" -a "$L" = "$J" \
			-a "$M" = "$J" -a "$N" = "$J" ] &>/dev/null;then
			echo "$J $K $L $M $N" $COUNT5>>45.hist;COUNT5=0
			fi	
		fi		
	done		
			
}
renice -n -10 "$$"		
while true
do
	_MATRIX
	_BIT
	_READ
	_TEST
	clear
done

And a viewer....

while :
do 
	echo -e "\n\t`date +%r`"
	echo '>>>>>>>>>>>>>>>>>'
	echo
	cat -n 42.hist|tail -5
	echo '>>>>>>>>>>>>>>>>>>>'
	echo
	cat -n 43.hist|tail -5
	echo '>>>>>>>>>>>>>>>>>>>>>>>'
	echo
	cat -n 44.hist|tail -5
	echo '>>>>>>>>>>>>>>>>>>>>>>>>>>'
	echo
	cat -n 45.hist|tail -5
	echo '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
	echo
	sleep 0.2
	clear
done

:)


Edited by ShaunPrawn, 07 August 2014 - 06:21 AM.


#2 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 07 August 2014 - 03:35 PM

Welcome aboard Shaun,

 

Nice code!