I understand why RANDOM is NOT random due its math behind it.
I have a BASH Script I have written long ago. I use it to work - or - manipulate files within as many different directories I want. Within all of the directories are image files.
the image files are used to display on the desktop screen background.
the script "randomizes" the files so that a different one is picked each time then displayed onto the desktop.
I use one IF statement to cycle through a case statement, then another case statement that uses the line of commands needed to display the image and within that line of commands I use shuf to select the image within whatever directory that is picked to use.
As anyone that has worked with anything that preforms a random "number" and lets it run - repeat the process again and again will notice that it is no longer being random. Rather the same numbers are being generated over and over again.
It has "metamorphose" into a pattern of seemingly random numbers.
as my script is really long because I use RANDOM itself in functions to change some of the arguments in the line of commands. If I post my BASH Script in its entirety it may easily confuse most people.
So I will only post the if and two case statements, if one wants to see more then just submit the proper paper work and I will post it in here.
The question is. does anyone know of a different or better means of using any type of means that uses random or an algorithm that will work in bash script and I can use to produce the same results of an absolute path and file name.jpg (png) to be returned for use?
This is a shortened version so you the reader will hopefully get the idea of how this is being done.
Code:
while true; do
if [[ "$wpaper" -eq 4 ]] ; then
{
wpaper=1
}
else
{
((++wpaper))
}
fi
case $wpaper in
1)
{
WALLPAPERS=/media/data/Naked-Fish
setpaper=1
}
;;
2)
{
WALLPAPERS=/usr/share/wallpapers/
setpapers=2
}
;;
3)
{
WALLPAPERS=/media/data/Dead-Flowers
setpaper=1
}
;;
4)
{
#just colors
setpaper=3
}
;;
esac
case $setpaper in
1)
{
find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' \) -print0 | shuf -n 15 -z | shuf -n 1 -z | xargs -0 \
mhsetroot -addd $(color) 3 -addd $(color2) 5 -addd $(color) 3 -addd $(tint) 8 -gradient "$(setGradient)" -fill
}
;;
2)
{
find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' \) -print0 | shuf -n 1 -z | xargs -0 mhsetroot -fs
}
;;
3)
{
mhsetroot -addd $(color) 3 -addd $(color2) 5 -addd $(color) 3 -addd $(tint) 8 -gradient "$(setGradient)"
}
;;
esac
#notes:
#find "$WALLPAPERS" -type f \( -name '*.jpg' -o -name '*.png' \) -print0 | shuf -n 3 -z | xargs -0 \
#mhsetroot -addd $(color) 3 -addd $(color2) 5 -addd $(color) 3 -addd $(tint) 8 -gradient "$(setGradient)" -fill
#mhsetroot -addd $(color) "$(addSetNum1)" -addd $(color2) "$(addSetNum2)" -gradient "$(setGradient)" \
# to set image to user specified size
#-dcenter 300x300
# -tint $(tint) -brightness "$(setContrast)" -dcenter 700x450
# ${setS} "${setI}" 450x500
#changes options ie -tile -fill -dia -center -flipimg then add the prams needed after
echo "sleep time changed to $(($nw/60)) minutes"
sleep "$nw"
done &