0

I have been trying to pipe random data into a program that is suppose to predict the next correct number. I want to run a infinite loop pipe for option 1 which leads to option 2 with another option with c to continue. The reason for this is for the AI to be trained in predicting patterns found in random generated numbers.

NOTE: When, I say option 1 and option 2 i mean by selecting option 1 it will display the following options "enter number 1 and enter number 2.

This is what the program looks like in the shell.

Select your choice.

1. Enter the newest number.

2. Find a new number.


-------------------------------------------------------------------

Select your choice.

1. Enter the newest number.

2. Find a new number.


 Enter number 1. 

 Enter number 2. 

 Enter c to continue or 0 to quite 

Pipes that I tried to get to work, but failed.

./RNGAI | echo "1" | shuf -i 1-26 -n1 | echo "2" | shuf -i 1-26 -n1 | echo "c" | ./RNGAI
./RNGAI | echo "1" | echo $((RANDOM%10))| ./RNGAI & echo "2" | echo $((RANDOM%10)) & echo "c" 

I have an error after trying some pipes. The pipes do technically work, however the RNGAI program throws errors show -nan every time it runs its loop with the pipe. Here are the pipes and scripts I tried to run

while true
do
echo 1
echo $ od -A n -N 2 -t u2  /dev/random
echo 2
echo $ od -A n -N 2 -t u2  /dev/random
echo c
done | ./RNGAI

Here are the pipes

 while :; do printf "%s\n" 1  seq 1 26 | sort -R | head -n 1 2  seq 1 26     | sort -R | head -n 1 c; done | ./RNGAI
 while :; do printf "%s\n" 1 od -A n -N 2 -t u2  /dev/random 2 $od -A n -N 2 -t u2  /dev/random c; done | ./RNGAI
 while :; do printf "%s\n" 1 shuf -i 1-26 -n1 2 shuf -i 1-26 -n1 c; done | ./RNGAI

Error the RNGAI program throws

   Select your choice.

   1. Enter the newest number.

   2. Find a new number.

      Enter number 1. 
      Enter number 2. 
      -nan
      -nan
       Enter c to continue or 0 to quite 
       Enter number 1. 
       Enter number 2. 
       -nan
       -nan

closed as unclear what you're asking by muru, Stephen Rauch, G-Man, user34720, countermode Jun 22 '17 at 11:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Good luck on the mission of "predicting patterns found in random generated numbers."! – Jeff Schaller Jun 21 '17 at 9:59
  • @JeffSchaller if the source is a pseudo-RNG, it's actually a good exercise. That's the reason why cryptographically secure RNGs are so important - all pseudo-RNGs become predictable given a sufficiently long history. – muru Jun 21 '17 at 12:43
  • This might be useful in cracking encryption. – Travis Wells Jun 21 '17 at 12:52
  • 1
    Possible duplicate of How do I redirect output to cd? – muru Jun 22 '17 at 4:24
  • 1
    Your pipes are meaningless. If you want to use the output of a command as argument to another command, use command substitution. See linked post. – muru Jun 22 '17 at 4:24
3

I think you're looking for this:

while true
do
    echo 1
    echo $((RANDOM % 10))
    echo 2
    echo $((RANDOM % 10))
    echo c
done | ./RNGAI

Or more concisely:

while :; do printf "%s\n" 1 $((RANDOM % 10)) 2 $((RANDOM % 10)) c; done | ./RNGAI

You want to pipe data into a program, then the input comes before the pipe:

<source of input> | <command that uses the input>
  • The pipes work, but the program is throwing errors. It says -nan every time when it is in loop. I even tried different commands to generate random numbers. Here is an example of what I tried to run in a script. while true do echo 1 echo $ od -A n -N 2 -t u2 /dev/random echo 2 echo $ od -A n -N 2 -t u2 /dev/random echo c done | ./RNGAI – Travis Wells Jun 21 '17 at 12:16
  • @TravisWells edit the question to include the actual code – muru Jun 21 '17 at 12:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.