Jump to content

[Solved]Linux random binary digits generation in the console (it is need the help of a linux geek :P )


frostysh

Recommended Posts

When I trying to convert the stupid *.png files to the stupid *.bam files that is need for my mod to BG2:EE I have obtain a super-mega idea how to make a matrix like console screen saver for linux!

So I started to read a lot of a stupid boring man pages and I have found program that called openssl rand this thing should to generate a pseudo-random bucket of data. But this data is looks very suxxy in the console :( . So I have found another crazy flexible and a crazy inopportune and a stupid program called xxd that can show a some data in 0101010010111111110101 format.

>openssl rand -out cool_e 8
-out means a name of a file in which will be wrote the data, 8 - this is a bit-size of data or byte-size, but who really cares about. :D .

>xxd -bits cool_e
this will show something like this.

0000000: 00110011 01101111 11001011 11111001 01010111 11111100  3o..W.0000006: 01001011 11011001                                      K.
but I need something like this one

0011001101101111110010111111100101010111111111000100101111011001
e.g. without the number of line rightward and without the symbolic column leftward.

HOW to do it?

 

Next I will generate a text file by using the python - this is a reptile programming language that I do not like and do not want to learn (but anyway I do not to learn any of a programming languages :p ).

python > cool_scrs.txtType "help", "copyright", "credits" or "license" for more information.>>> print (' openssl rand -out cool_e 8; xxd -bits cool_e; sleep 2;'*200)>>>
the ; program-deliminator that first execute the command (program, etc) from a left side then waiting until it done his job and then execute command from a right side. sleep - this thing can turn console to the idle state for a next n +/-1 seconds :D.

The * asterisk means that python will draw the message on the screen/file multiple time (200 times in my case)

So after python done his job I will obtain the file

openssl rand -out cool_e 8; ...................... sleep 2;
Thex CTRL-COPY, CTRL-PASTE to the console, delete the last ; and press ENTER :beholder:

I am genius ! :crazy:

But how to cut off the address and a symbol columns and make a plain 01010110111100 stuff??? Is anybody knows how to perform this action?

 

Thanx for the answers.

 

---edited--- now I edited this post and all inside the 'code' BBTag is automagically transformed to telegraph string... this is an 'amazing' :/ .

Link to comment
openssl rand -out /dev/stdout 128 | xxd -bits -g 0 | sed 's,\S* ,,; s, [^ ]*$,,; s,[^01]*,,g'

just change 128 to something bigger if you want more.

 

Or simply do this:

xxd -bits -g 0 /dev/urandom | awk '{print $2}'

the fact that awk buffers creates enough of a delay for it to look nicer.

Link to comment

 

 

openssl rand -out /dev/stdout 128 | xxd -bits -g 0 | sed 's,\S* ,,; s, [^ ]*$,,; s,[^01]*,,g'
just change 128 to something bigger if you want more.

 

Or simply do this:

xxd -bits -g 0 /dev/urandom | awk '{print $2}'
the fact that awk buffers creates enough of a delay for it to look nicer.
Yay! It it is a little bit better implementation that I proposed :D This is works. Thanx.

 

If you will have some free time explain to me the meaning of a different programs that used in , please. Such as:

>sed 's,\S* ,,;'
So sed is a symbol editor of output or a text stuff (I have read some info sed), the s option is 'replace by pattern + flags' , "\S*" - what is that? "\"[\b] - this a pattern symbol, but what the meaning of S*? and then ' ,,' this is for what? ";" this for give control to the next option after previous one is done.

s, [^ ]*$,,;
again s option and again ", " - but for what? "[^ ]" - this is mean all symbols but that are not -spaces- ( ^ - means reverse), and why did entered this "*$" - this something for -spaces- too? again two commas that I can't recognize...

s,[^01]*,,g
This is most interesting party :p , why the hell do you need to reverse the 01 combination? again commas??? and that g.???

This is what I have found in info sed stuff.

The syntax of the `s' (as in substitute) command is
`s/REGEXP/REPLACEMENT/FLAGS'.  The `/' characters may be uniformly
replaced by any other single character within any given `s' command.
The `/' character (or whatever other character is used in its stead)
can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\'
character.
`^'
     Matches the null string at beginning of the pattern space, i.e.
     what appears after the circumflex must appear at the beginning of
     the pattern space.
`g'
     Apply the replacement to _all_ matches to the REGEXP, not just the
     first.
`$'
     This address matches the last line of the last file of input, or
     the last line of each file when the `-i' or `-s' options are
     specified.
`$'
     It is the same as `^', but refers to end of pattern space.  `$'
     also acts as a special character only at the end of the regular
     expression or subexpression (that is, before `\)' or `\|'), and
     its use at the end of a subexpression is not portable.
`[LIST]'
`[^LIST]'
     Matches any single character in LIST: for example, `[aeiou]'
     matches all vowels.  A list may include sequences like
     `CHAR1-CHAR2', which matches any character between (inclusive)
     CHAR1 and CHAR2.
`a*b'
     Matches zero or more `a's followed by a single `b'.  For example,
     `b' or `aaaaab'.
`\CHAR'
     Matches CHAR, where CHAR is one of `$', `*', `.', `[', `\', or `^'.
     Note that the only C-like backslash sequences that you can
     portably assume to be interpreted are `\n' and `\\'; in particular
     `\t' is not portable, and matches a `t' under most implementations
     of `sed', rather than a tab character.
This is a some kind of magic that I can not understand :yellowbeholder:

 

Whatever , both ways works very well but

xxd -bits -g 0 /dev/urandom | awk '{print $2}'
"{print $2}" - what is that O_o . The magic... indeed.

is making more the cool continuous flood then mine first attempt with a help of python :p. But this way makes more CPU load resource (~70% in my case.. :( ), that is not good. And both ways creating to little-wide flood i.e.

101011001011011001100000100001001001001101010110
40 symbols length maximum , regardless of how wide is my console emulator .

But I need something that taking the less CPU resources and making a wider flood of 001101010011100, so I can make console emulator wider or 'fullscreen' it and then looking at this cool SMOOTH slide bits flow ^_^ .

 

Again thanx,

Link to comment

sed was just used to delete everything but the middle column — in the second example awk was used, which looks much nicer.

 

For wider lines and an output limit, just add more options:

xxd -c 256 -l 200 -bits -g 0 /dev/urandom  | awk '{print $2}'

then you can put it in a loop and sleep as desired.

Link to comment

 

sed was just used to delete everything but the middle column — in the second example awk was used, which looks much nicer.

 

For wider lines and an output limit, just add more options:

xxd -c 256 -l 200 -bits -g 0 /dev/urandom  | awk '{print $2}'
then you can put it in a loop and sleep as desired.
Yay the magic! Looks super cool. Sorry if I am too boring, but I have some questions, again :p.

So

awk '{print $2}'
makes visible only second column? Nice.

this is an apart of the result of program. in 72x30 size of console emulator.

>xxd -c 256 -l 2000 -bits -g 0 /dev/urandom  | awk '{print $2}'
10011110110001001101110111001101101010011111001010001011101011010011111111101111010001110010100000011110011000011100010010010000000110110101011011110100100100110011110100010111100111010011110010101010101001101001010100011101001010010000101110100111010100110001110101100001110001000011010100001000001000111101110011101111101100110101100101000011110101011111100111110000010110011101110101110010
110100001110100011111101011100110111010101010010100111010101111011110010001000011011000101011111101001010101010101010110101101010101110101010011000100000101110000111011110100100001111100000000101000100100010110010011111011000100101111110001011000100101001011111001111110111011101110110010000011010001101101011001010001100010110001010111010111010100000111010011
As we can see, we have blank line. This empty lone will be absent in 32xN, 64xN, 128xN, ... size of console emulator. I think this is because

>xxxd -c 256
the number of columns option in xxd program, 256 is a max value.

So 1,2,3,4,...,256 column and xxd starting new line . :party:

Is the sed has this 256-limitation? I want to delete this empty lines regardless of a size of console emulator. :beholder:

Link to comment

 

to remove all newlines, just pipe it to tr -d '\n' .

Yep baby! :goodwork:

>xxd -cols 256 -len 2000 -bits -groupsize 0 /dev/urandom 
#We given order to xxd to read a /dev/urandom  and and to show binary digits and #to format the output by 256 columns per line don't separate in groups and total #length is 2000 bytes.
# 
| awk '{print $2}'
#Now we given the control of output of xxd to the awk via so-called pipeline #stuff '|' that showing only second column (3 column in total, 1 - number of #line, second actually 111001011, and #third a weird symbols.) 
#
| tr --delete "\n"
#And finally we given control to the tr that just deletitng newline character #'\n' that xxd placing after 256th column.
#P.S. Stupid xxd do not recognize even his own '-groupsize' so replace it to #'-g' 
#
now /dev/urandom is one my favorite devices :p . Thanx again, I will try somewhere some-when somehow to loop it and sleep sleep it. :cooool:
Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...