memory size

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

memory size

Eben King
I wrote this Q+D script to demonstrate how much (how little) text was a
kilobyte (my friend and I were talking about our first computers).  It can
be adjusted for any amount.  It takes no arguments, all adjustments are done
by editing the source.  Spaces don't count toward the character total.

#! /bin/bash
wordlength=5
characters=1024
# end configurable options

counter=0
randmax=32768 # this has no significance to bash
spacecode=32 # decimal ASCII code for a space
spacelimit=$(( randmax - randmax / ( wordlength + 1 ) )) # if RANDOM > this,
print a space

while [ $counter -lt $characters ] ; do
   thisrandom=$RANDOM # RANDOM = bash PRNG
   if [ $thisrandom -gt $spacelimit ] ; then
     charactercode=32
   else
     charactercode=$(( 97 + thisrandom % 26 )) # 97=ASCII code for "a"
     counter=$(( counter + 1 ))
   fi
   echo $charactercode P
done | dc | fold -w 80 -s
echo

--
-eben    [hidden email]    ebmanda.redirectme.net:81
LIBRA:  A big promotion is just around the corner for someone
much more talented than you.  Laughter is the very best medicine,
remember that when your appendix bursts next week.  -- Weird Al
_______________________________________________
slug mailing list
[hidden email]
https://www.suncoastlug.org/mailman/listinfo/slug
Loading...