Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Bash, 162 104 bytes

Modification of Zachary's answerZachary's answer on a related question, with massive improvements by manatwork:

s='-\|/'
for x in {0..100};{
printf "\rloading ${s:x%4:1} $x %%"
sleep `printf .%03d $[RANDOM%750+1]`
}

I had to look up how to do random numbers in bash.

Ungolfed / Explained

s='-\|/'
for x in {0..100}
{
    # \r returns the carriage to the beginning of the current line.
    # ${s:x%4:1} grabs a substring from s, at index x%4, with a length of 1.
    printf "\rloading ${s:x%4:1} $x %%"

    # "$RANDOM is an internal bash function that returns
    #   a pseudorandom integer in the range 0 - 32767."
    # .%03d is a dot followed by a base-ten number formatted to 3 places,
    #   padded with zeros if needed.
    # sleep accepts a floating point number to represent milliseconds.
    sleep `printf .%03d $[RANDOM%750+1]`
}

Bash, 162 104 bytes

Modification of Zachary's answer on a related question, with massive improvements by manatwork:

s='-\|/'
for x in {0..100};{
printf "\rloading ${s:x%4:1} $x %%"
sleep `printf .%03d $[RANDOM%750+1]`
}

I had to look up how to do random numbers in bash.

Ungolfed / Explained

s='-\|/'
for x in {0..100}
{
    # \r returns the carriage to the beginning of the current line.
    # ${s:x%4:1} grabs a substring from s, at index x%4, with a length of 1.
    printf "\rloading ${s:x%4:1} $x %%"

    # "$RANDOM is an internal bash function that returns
    #   a pseudorandom integer in the range 0 - 32767."
    # .%03d is a dot followed by a base-ten number formatted to 3 places,
    #   padded with zeros if needed.
    # sleep accepts a floating point number to represent milliseconds.
    sleep `printf .%03d $[RANDOM%750+1]`
}

Bash, 162 104 bytes

Modification of Zachary's answer on a related question, with massive improvements by manatwork:

s='-\|/'
for x in {0..100};{
printf "\rloading ${s:x%4:1} $x %%"
sleep `printf .%03d $[RANDOM%750+1]`
}

I had to look up how to do random numbers in bash.

Ungolfed / Explained

s='-\|/'
for x in {0..100}
{
    # \r returns the carriage to the beginning of the current line.
    # ${s:x%4:1} grabs a substring from s, at index x%4, with a length of 1.
    printf "\rloading ${s:x%4:1} $x %%"

    # "$RANDOM is an internal bash function that returns
    #   a pseudorandom integer in the range 0 - 32767."
    # .%03d is a dot followed by a base-ten number formatted to 3 places,
    #   padded with zeros if needed.
    # sleep accepts a floating point number to represent milliseconds.
    sleep `printf .%03d $[RANDOM%750+1]`
}
Added improvements from manatwork.
Source Link

Bash, 162162 104 bytes

Modification of Zachary's answer on a related question, with massive improvements by manatwork:

s='/-\|'\|/'
for x in {0..100};do;{
printf "\rloading ${s:i=++i%4x%4:1} $x %%"
y=0;while [ $y -le 0 ];do y=$RANDOM;let y%=751;done
sleep $(echo`printf "scale=3;$y/1000"|bc).%03d $[RANDOM%750+1]`
done}

I had to look up how to do random numbers and floating point math in bash.

Ungolfed / Explained

s='/-\|'\|/'
for x in {0..100}
do{
        # \r movesreturns the carriage to the beginning of the current line.
        # ${s:i=++i%4x%4:1} grabs a substring from s, at index i=++i%4x%4, with a length of 1.
        # (i=++i%4 is black magic to me, sorry)
        printf "\rloading ${s:i=++i%4x%4:1} $x %%"

        y=0
        # Ensure that y is not less than or equal to zero.
        while [ $y -le 0 ]
        do
                # "$RANDOM is an internal bash function that returns
                #   a pseudorandom integer in the range 0 - 32767."
                y=$RANDOM
                # Ensure that y is less than 751 via modulo.
                let y %= 751
        done

    %03d is a dot #followed sleepby acceptsa floatingbase-ten pointnumber numbersformatted to sleep for3 millisecondsplaces,
        #   but bash can't nativelypadded dowith floatingzeros pointif mathneeded.
        # bc (a posix calculator) returns floatssleep ifaccepts youa specifyfloating apoint decimalnumber placeto withrepresent scalemilliseconds.
        sleep $(echo "scale=3; $y / 1000"`printf |.%03d bc)$[RANDOM%750+1]`
done}

Bash, 162 bytes

Modification of Zachary's answer on a related question:

s='/-\|'
for x in {0..100};do
printf "\rloading ${s:i=++i%4:1} $x %%"
y=0;while [ $y -le 0 ];do y=$RANDOM;let y%=751;done
sleep $(echo "scale=3;$y/1000"|bc)
done

I had to look up how to do random numbers and floating point math in bash.

Ungolfed / Explained

s='/-\|'
for x in {0..100}
do
        # \r moves the carriage to the beginning of the current line.
        # ${s:i=++i%4:1} grabs a substring from s, at index i=++i%4, with a length of 1.
        # (i=++i%4 is black magic to me, sorry)
        printf "\rloading ${s:i=++i%4:1} $x %%"

        y=0
        # Ensure that y is not less than or equal to zero.
        while [ $y -le 0 ]
        do
                # "$RANDOM is an internal bash function that returns
                #   a pseudorandom integer in the range 0 - 32767."
                y=$RANDOM
                # Ensure that y is less than 751 via modulo.
                let y %= 751
        done

        # sleep accepts floating point numbers to sleep for milliseconds,
        #   but bash can't natively do floating point math.
        # bc (a posix calculator) returns floats if you specify a decimal place with scale.
        sleep $(echo "scale=3; $y / 1000" | bc)
done

Bash, 162 104 bytes

Modification of Zachary's answer on a related question, with massive improvements by manatwork:

s='-\|/'
for x in {0..100};{
printf "\rloading ${s:x%4:1} $x %%"
sleep `printf .%03d $[RANDOM%750+1]`
}

I had to look up how to do random numbers in bash.

Ungolfed / Explained

s='-\|/'
for x in {0..100}
{
    # \r returns the carriage to the beginning of the current line.
    # ${s:x%4:1} grabs a substring from s, at index x%4, with a length of 1.
    printf "\rloading ${s:x%4:1} $x %%"

    # "$RANDOM is an internal bash function that returns
    #   a pseudorandom integer in the range 0 - 32767."
    # .%03d is a dot followed by a base-ten number formatted to 3 places,
    #   padded with zeros if needed.
    # sleep accepts a floating point number to represent milliseconds.
    sleep `printf .%03d $[RANDOM%750+1]`
}
Remove unnecessary quote marks, explained code.
Source Link

Bash, 164162 bytes

Modification of Zachary's answer on a related question:

s='/-\|'
for x in {0..100};do
printf "\rloading ${s:i=++i%4:1} $x %%"
y=0;while [ "$y"$y -le 0 ];do y=$RANDOM;let y%=751;done
sleep $(echo "scale=3;$y/1000"|bc)
done

I had to look up how to do random numbers and floating point math in bash.

Ungolfed / Explained

s='/-\|'
for x in {0..100}
do
        # \r moves the carriage to the beginning of the current line.
        # ${s:i=++i%4:1} grabs a substring from s, at index i=++i%4, with a length of 1.
        # (i=++i%4 is black magic to me, sorry)
        printf "\rloading ${s:i=++i%4:1} $x %%"

        y=0
        # Ensure that y is not less than or equal to zero.
        while [ $y -le 0 ]
        do
                # "$RANDOM is an internal bash function that returns
                #   a pseudorandom integer in the range 0 - 32767."
                y=$RANDOM
                # Ensure that y is less than 751 via modulo.
                let y %= 751
        done

        # sleep accepts floating point numbers to sleep for milliseconds,
        #   but bash can't natively do floating point math.
        # bc (a posix calculator) returns floats if you specify a decimal place with scale.
        sleep $(echo "scale=3; $y / 1000" | bc)
done

Bash, 164 bytes

Modification of Zachary's answer on a related question:

s='/-\|'
for x in {0..100};do
printf "\rloading ${s:i=++i%4:1} $x %%"
y=0;while [ "$y" -le 0 ];do y=$RANDOM;let y%=751;done
sleep $(echo "scale=3;$y/1000"|bc)
done

I had to look up how to do random numbers and floating point math in bash.

Bash, 162 bytes

Modification of Zachary's answer on a related question:

s='/-\|'
for x in {0..100};do
printf "\rloading ${s:i=++i%4:1} $x %%"
y=0;while [ $y -le 0 ];do y=$RANDOM;let y%=751;done
sleep $(echo "scale=3;$y/1000"|bc)
done

I had to look up how to do random numbers and floating point math in bash.

Ungolfed / Explained

s='/-\|'
for x in {0..100}
do
        # \r moves the carriage to the beginning of the current line.
        # ${s:i=++i%4:1} grabs a substring from s, at index i=++i%4, with a length of 1.
        # (i=++i%4 is black magic to me, sorry)
        printf "\rloading ${s:i=++i%4:1} $x %%"

        y=0
        # Ensure that y is not less than or equal to zero.
        while [ $y -le 0 ]
        do
                # "$RANDOM is an internal bash function that returns
                #   a pseudorandom integer in the range 0 - 32767."
                y=$RANDOM
                # Ensure that y is less than 751 via modulo.
                let y %= 751
        done

        # sleep accepts floating point numbers to sleep for milliseconds,
        #   but bash can't natively do floating point math.
        # bc (a posix calculator) returns floats if you specify a decimal place with scale.
        sleep $(echo "scale=3; $y / 1000" | bc)
done
Changed y%=750 to y%=751 because it wasn't inclusive.
Source Link
Loading
Corrected misattributed floating point math info.
Source Link
Loading
Source Link
Loading