how to display 3 random pictures out of 8 using bash - bash

I have 8 images in a directory.
the path is /blabla.com/img.
I need to access this path and choose 3 out of 8 randomly and display those.
If 3 pics are the same, it should echo "yeeey".
Otherwise, "neeey" and record these responses in a text file.

I am not going to do your homework for you!
However I can give you some insight:
store your 8 file names in an array
call $RANDOM % 8 3 times and store the value in 3 index variables
use the 3 index variables to extract your 3 files
use sha256sum, sha512sum or md5sum to compute the signature of your images and store the result in 3 variables
compare the values of the 3 variables if they are the same echo "yeeey" else echo "neeey"
if on top of that you want to display the picture as written in your post you could call eog or other similar tool with the finename as parameter and of course in background, with a & at the end of the command call.
Good luck with your assignment and let me know if you need help!

let's array an array of distinct elements (for example 8):
array=({A..H})
(1) use RANDOM special variable modulo the number of elements to get a random number between 0 and number-1 inclusive
number=$((RANDOM%${#array[#]}))
the first random element is
first=${array[number]}
remove the element from array and reassign the array to reindex without gap (declare -p array to see)
unset array[number]
array=("${array[#]}")
restart from (1)

Related

Mathematica removing columns cannot take positions through 2 to 3 error

I have a matrix consisting of 3 rows and 4 columns of which which I require the central two columns.
I have attempted extracting the central two columns as follows:
a = a[[2 ;; 3, All]];
On the mathematica function list, the first entry in a[[2 ;; 3, All]] represents the rows and the second the columns, however whenever I try a[[All,2 ;; 3]] it removes the top row rather than the two columns. For some reason they seem inverted. I tried going around this by switching the entries around however, when I use a[[2 ;; 3, All]], I get the error: Part: Cannot take positions 2 through 3 in a.
I cannot wrap my head around why this keeps happening. It also refuses to extract single columns from the matrix as well.
You show that you are assigning a variable to itself and then saying that things don't work for you. That makes me think you might have previously made assignments to variables and the results of that are lurking in the background and might be responsible for what you are seeing.
With a fresh start of Mathematica, before you do anything else, try
mat={{a,b,c,d},
{e,f,g,h},
{i,j,k,l}};
take23[row_]:=Take[row,{2,3}];
newmat = Map[take23, mat]
Map performs the function take23 on every row and returns a list containing all the results giving
{{b,c},
{f,g},
{j,k}}
If need be you can abbreviate that to
newmat = Map[Take[#,{2,3}]&, mat]
but that requires you understand # and & and it gives the same result.
If necessary you can further abbreviate that to
newmat = Take[#,{2,3}]& /# mat
Map is widely used in Mathematica programming and can do many more things than just extract elements. Learning how to use that will increase your Mathematica skill greatly.
Or if you really need to use ;; then this
newmat = mat[[All, 2;;3]]
I interpret the documentation for that to mean you want to do something with All the rows and then within each row you want to extract from the second to the third item. That seems to work for me and instantly returns the same result.
If you instead wrote
newmat = mat[[1;;2, 2;;3]]
that would tell it that you wanted to work from row 1 down to row 2 and within those you want to work from column 2 to column 3 and that gives
{{b,c},
{f,g}}

SPSS- assigning mulitple numeric codes to one variable

I am trying to assign multiple codes to existing variables. I am using the syntax below, but it will only assign the first code entered for that hosp.id.number.
Syntax example:
Do if (hosp.id.number=9037) or (hosp.id.number=1058) or (hosp.id.number=11256).
Compute role_EM_communication=10.
Else if (hosp.id.number=9037.
Compute role_EM_communication=11.
End if.
Execute.
hosp.id.number needs to be coded 10 and 11, but it will only code it at 10. Anyway to rephrase so that SPSS will accept 2 or more codes for a variable such as hosp.id.number?
Your role_EM_communication variable is a single variable, but from what you are saying, I think you need it to be a set (for the same record, it could take on more than just one code). So you need to create n variables named role_EM_communication_1 to role_EM_communication_n, where n is the maximum number of codes you estimate will be possible for one record.
For your example, it would translate like this:
create the 2 variables:
vector role_EM_communication_ (2, f2.0).
do the first recode:
if any(hosp.id.number,9037,1058,11256) role_EM_communication_1=10.
very important - execute the recode
exe.
check if the first variable has data, and populate the second variable if true:
if miss(role_EM_communication_1) and any(hosp.id.number,9037) role_EM_communication_1=11.
if ~miss(role_EM_communication_1) and any(hosp.id.number,9037) role_EM_communication_2=11.
exe.

How do I create random in Eclipse?

I have 10 images and I want them to be prompt out randomly. What code should I use? I'm still an amateur so I hope I could get some answers here... The images are named like 'pic1', 'pic2' and so on. is it possible to get the number from the file name and use Math.random() ?
Store the pics in an Array.
Say array index is from 0 to 9
Use Java Math.random to get random number.
You need to multiply its result by 10 get indexes in your range

Stata rnormal()

I want to generate a fixed random variable ~N(0,10) for every observation for future computation.
gen X=rnormal (0,10)
list X
Blank
How can I see what value of X is being generated?
You were probably using an empty dataset when you issued these commands. In that case you would first need to tell Stata how many observations your dataset contains. For that you need to use the set obs command, so something like:
. set seed 12345
. set obs 10
obs was 0, now 10
. gen x = rnormal(0,10)
. list, clean
x
1. -9.580833
2. -2.907274
3. 8.45202
4. 8.617108
5. -12.19151
6. 9.457337
7. 1.722469
8. -13.29949
9. -11.5291
10. 25.1646
Think of what would happen when you did not use set obs. In that case Stata would see gen x = rnormal(0,10) and think "ok, I need to create random draws from a normal distribution, but how many?". If you had a dataset open, then it would answer "as many as there are observations in the dataset". If you had no dataset open, then the answer would still be "as many as there are observations in the dataset", but that happens to be 0.
Edit:
If you just want one number you are best of using scalars and not variables. In Stata a scalar refers to a single number and a variable refers to a single column in your dataset. For scalars it is best to use temporary names, as they share the same namespace as variables but variables take precedence when it comes to abreviations, which can lead to unexpected behaviour. So you could do something like:
. tempname a
. scalar `a' = rnormal(0,10)
. di `a'
10.737423

Bash: identify repeating string in an array

I have a script that detects crop values before I start video encoding.
I do several probes at a certain interval, say every 100th frame.
If all the crop values for all the probed frames match then there is no problem and the script kicks in the encoding function. If crop values differ then script exits with an error and I need to pick the correct crop value manually which is annoying.
So, instead of exiting the script with an error I would rather pick the "best" possible value which, in this situation, is the number that repeats the most.
So how do I pick a string out of the collection that repeats the most?
Say, I put all the crop values in an array.
Crop=('3' '4' '3' '5' '7' '3' '7');
So in this situation I would pick value '3' as it repeats most often.
How can I do it programmatically in Bash?
Thanks.
-- EDIT --
I do apologize, to simplify my question I might have confused some of you.
The real crop values look like this "720:568:0:4".
Pure bash solution using an associative array (bash version 4 needed):
#! /bin/bash
crop=(3 4 3 5 7 3 7)
declare -A count
max=0
for c in "${crop[#]}" ; do
(( count[$c]++ ))
if (( count[$c] > max )) ; then
max=${count[$c]}
idx=$c
fi
done
echo $idx

Resources