[Question]
  [
Make a fake loader just like this :  
![](https://i.stack.imgur.com/zk5Tr.gif) 
## Parameters :
* Display `loading` (space) one of these cyclically`-\|/` (space) (percentage counter from 0-100) then a `%`.
* The percentage counter is supposed to increment by 1 every time the display changes.
* The time taken by counter to jump to next iteration is random. Any kind of random will do as long as the function/method is capable of generating all random integers having probability > 0 in range `1<= ms <=750` here `ms` being time in milliseconds.
* **Start** at `loading - 0 %`.
* **End** at `loading - 100 %`.
* NO INPUT is required.
* submit a **full** program or **function** or whatever similar.
The code that I used : 
## C++
```
#include<stdio.h>
#include<time.h>
#include<windows.h>
int main()
{
    srand(time(NULL));
    char a[15],b[]="-\\|/";
    int i=0,j=0,ms;
    while(j<101)
    {
        (i<3)?i++:i=0;
        wsprintf(a,"loading %c %d ",b[i],j++);
        printf(a);puts("%");
            //This part is to make the output look cool
        switch(rand()%9)
        {
            case 0:ms=1;break;
            case 1:ms=2;break;
            case 2:ms=5;break;
            case 3:ms=10;break;
            case 4:ms=15;break;
            case 5:ms=20;break;
            case 6:ms=25;break;
            case 7:ms=50;break;
            case 8:ms=500;
        }
        Sleep(ms);  //Otherwise this is supposed to be random
        if(j<101)   //like this Sleep(rand()%750+1);
        system("cls");
    }
}
```
## Winner
* the code with least bytes wins.
  
[Answer]
## Powershell, ~~71~~ ~~68~~ 65 Bytes
Similar to <https://codegolf.stackexchange.com/a/101357/59735>
Saved 3 bytes by not being an idiot (left the ... on loading)
-3 thanks to VisualMelon
changed 750 -> 751 to make sure 750 is included.
```
0..100|%{cls;"loading $("|/-\"[$_%4]) $_ %";sleep -m(random 751)}
```
Explanation:
```
0..100|%{                                  #For range 0-100...
    cls                                    #Clear Display
    "loading $("|/-\"[$_%4]) $_ %"    #Display the current string
    sleep -m(random 750)                  #Sleep random ms up to 750
}
```
Updated gif
[![enter image description here](https://i.stack.imgur.com/pq947.gif)](https://i.stack.imgur.com/pq947.gif)
[Answer]
# Python 2, ~~119~~ ~~113~~ 112 Bytes
I had originally gone with the random amount being `random()/.75`, however the endpoint wouldn't be included. There isn't much difference from this to the other question for the infinite load time except for the randomness and the fact that it actually ends.
```
import time,random as r
for i in range(101):print'\rLoading','-\|/'[i%4],i,'%',;time.sleep(r.randint(1,750)/1e3)
```
*thanks to Jonathan Allan for saving 6 bytes, and DJMcMayhem for saving a byte!*
[Answer]
# [MATL](https://github.com/lmendo/MATL), 45 bytes
```
101:"'loading'O'-\|/'@)O@qVO37&hD750Yr100/&Xx
```
Example run in the offline compiler:
[![enter image description here](https://i.stack.imgur.com/Ea0Ly.gif)](https://i.stack.imgur.com/Ea0Ly.gif)
Or try it at [MATL Online!](https://matl.io/?code=101%3A%22%27loading%27O%27-%5C%7C%2F%27%40%29O%40qVO37%26hD750Yr100%2F%26Xx&inputs=&version=19.6.0)
### Explanation
```
101:          % Push array [1 2 ... 101]
"             % For each
  'loading'   %   Push this string
  O           %   Push 0. When converted to char it will be displayed as a space
  '-\|/'      %   Push this sring
  @)          %   Modular index into this string with iteration index
  O           %   Push 0
  @q          %   Iteration index minus 1
  V           %   Convert to string
  O           %   Push 0
  37          %   Push 37, which is ASCII for '%'
  &h          %   Concatenate horizontally into a string, Numbers are converted to char
  D           %   Display
  750Yr       %   Random integer with uniform distribution on [1 2 ... 750]
  100/        %   Divide by 100
  &Xx         %   Pause that many tenths of a second and clear screen
              % End (implicit)
```
[Answer]
## Batch, 185 bytes
```
@set s=-\!/
@for /l %%i in (0,1,100)do @call:l %%i
@exit/b
:l
@cls
@set c=%s:~0,1%
@set s=%s:~1%%c%
@echo Loading %c:!=^|% %1 %%
@set/aw=%random%%%751
@ping>nul 1.1 -n 1 -w %w%
```
The timing is fairly poor unfortunately, but Batch doesn't have anything better to use than `ping`.
[Answer]
## [\*><>](http://esolangs.org/wiki/Starfish) (Starfish), ~~86~~ 82 bytes
```
| v1*aoooooooo"loading K"&0"-\|/"
!0x1! +
%$<.0+af{od;?)*aa&:&Soono$&+1:&"  %"{o:}
```
[Try it here!](https://starfish.000webhostapp.com/?script=D4AgbgjAVAhg9gxCBEAbOMAmBLAdgcxAGlkAyABmQFoAdYAemQCgBCcgDwhZAGomBSACQAeAHTkeMAGYBvOJgDcAfgCUsGKQBcpAMoJccQaR4RtyECH7I5mgL5A)
~~This may be able to be golfed more, but I don't see anything super obvious. It sleeps 100ms, 400ms, or 700ms, if this isn't random enough, let me know!~~
Thanks to @TealPelican for saving me 4 bytes and making it much more random!
The biggest challenges I found (while still trying to keep it small) were randomness, and actually outputting "loading - 100 %" at the end, instead of just exiting at my nearest convenience :p.
[Answer]
# [Perl 6](https://perl6.org), 67 bytes
```
for |<- \ | />xx* Z 0..100 {print "\rloading $_ %";sleep .750.rand}
```
## Expanded:
```
for
  # produce a list of all the pairs of values
  |<- \ | /> xx *   # a flat infinite list of "clock faces"
  Z                 # zipped with
  0 .. 100          # all the numbers from 0 to 100 inclusive
  # &zip / &infix:<Z> stop on the shortest list
{
  # ｢$_｣ will look something like ｢("/", 39)｣
  # when it is coerced to a Str, all of its elements
  # will be coerced to Str, and joined with spaces
  print "\rloading $_ %";
  sleep .750.rand
}
```
[Answer]
# Javascript (ES6), ~~128~~ ~~118~~ ~~116~~ ~~115~~ ~~112~~ ~~110~~ 109 bytes
This seems to work perfectly fine, even with this sketchy source of "random" numbers.
```
(X=_=>setTimeout(i>99||X,1+new Date%750,document.body.innerHTML=`<pre>Loading ${'-\\|/'[i%4]} ${i++}%`))(i=0)
```
---
**Alternative 1**, Javascript + HTML, 16 + 84 bytes
This one uses an already-existing element to display the remaining content:
```
(X=_=>setTimeout(i>99||X,1+new Date%750,a.innerHTML=`${'-\\|/'[i%4]} ${i++}%`))(i=0)
```
```
Loading <a id=a>
```
**Alternative 2**, 95 bytes
If I can assume a tab is opened and that you're pasting this into the console:
```
(X=_=>setTimeout(i>99||X,1+new Date%750,document.title=`Loading ${'-\\|/'[i%4]} ${i++}%`))(i=0)
```
Instead of showing the HTML, the title of the document will change.
---
Thank you to [@user2428118](https://codegolf.stackexchange.com/users/13486/user2428118) for saving 2 bytes!
[Answer]
# F#, 118 bytes
```
async{let r=System.Random()
for i in 0..100 do printf"\rLoading %O %d %%""|/-\\".[i%4]i;do!Async.Sleep(r.Next(1,750))}
```
In order to run this snippet, pass it into `Async.Start` or `Async.RunSynchronously`.
[Answer]
# PHP, ~~90~~ ~~83~~ ~~80~~ ~~78~~ ~~77~~ Bytes
**77:**
The closing `;` is not needed.
```
for(;$i<101;usleep(rand(1,75e4)))echo"\rloading ",'-\|/'[$i%4],' ',$i+++0,'%'
```
78:
While looking for another workaround to get a 0 initially without initializing the variable I came up with this:
```
for(;$i<101;usleep(rand(1,75e4)))echo"\rloading ",'-\|/'[$i%4],' ',$i+++0,'%';
```
Changed back to echo to win a few bytes as I only used printf to force-format as int. By incrementing the incremented $i with 0 I get a valid integer. By using single quotes as string delimiter the backslash does not need to be escaped, resulting in another byte freed
80:
Moving the increment of $i from the last for-section to the prinf gave me another 3 off. (See comments below)
```
for(;$i<101;usleep(rand(1,75e4)))printf("\rloading %s %d%%","-\\|/"[$i%4],$i++);
```
83:
Removed init of a variable with the loaderstates.
```
for(;$i<101;usleep(rand(1,75e4)),$i++)printf("\rloading %s %d%%","-\\|/"[$i%4],$i);
```
90:
I tried removing the init of $i to gain some bytes, as I had to add quite a few to enable the loader animation. printf adds 2 as opposed to echo, but formatting NULL as an integer results in 0.
```
for($l='-\|/';$i<101;usleep(rand(0,750)*1e3),$i++)printf("\rloading %s %d%%",$l[$i%4],$i);
```
[Answer]
# Groovy, ~~113~~ 87 bytes
***-36 bytes thanks to lealand***
```
{p=-1;101.times{print"\rLoading ${"-\\|/"[p++%4]} $p%";sleep Math.random()*750as int}}​
```
[Answer]
# Bash, ~~162~~ 104 bytes
Modification of [Zachary's answer](https://codegolf.stackexchange.com/a/101310) 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](http://www.tldp.org/LDP/abs/html/randomvar.html) 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]`
}
```
[Answer]
**C#, 170 149 135 Bytes**
```
()=>{for(int i=0;i++<=100;System.Threading.Thread.Sleep(new Random().Next(1,750)))Console.Write($"\rloading {@"-\|/"[i % 4]} {i} %");};
```
Ungolfed:
```
static void l()
{
    for (int i = 0; i <= 100; System.Threading.Thread.Sleep(new Random().Next(1, 750)))
        Console.Write($"\rloading {@"-\|/"[i % 4]} {i} %");   
}
```
I won't guarantee that every character in this is right, please correct me if there are compilation errors. I had to type the whole thing on my phone so I might have accidentally included some errors... ¯\_(ツ)\_/¯
I hope you guys forgive me that
Tested it on my PC, works like a charm and I even saved a whole 20 bytes thanks to pmbanka :)
[Answer]
# C ~~112~~ 103 bytes
Saved 9 bytes thanks to @G. Sliepen. Not very exciting, just a golf of your C++ answer basically. Also not a very exciting random function. I thought about `Sleep(c[i%4])`, or `Sleep(i)` but they're not random at all!
```
#import<windows.h>
i;f(){for(;i<101;printf("\rloading %c %d %%","-\\|/"[i%4],i++),Sleep(rand()%750+1));}
```
Ungolfed:
```
#include <windows.h>
int i;
void f() {
  for(;i<101;) {
    printf("\rloading %c %d %%", "-\\|/"[i%4], i++);
    Sleep(rand()%750+1);
  }
}
```
[Answer]
## Mathematica, 133 Bytes
```
Dynamic[If[x<100,x++,,x=0];Row@{"Loading ",StringPart["-\|/",1+x~Mod~4]," ",x,"%"},
    UpdateInterval:>[[email protected]](/cdn-cgi/l/email-protection),TrackedSymbols:>{}]
```
This will run once, assuming x is undefined. `Clear@x` will restart it.
55 characters tied up in verbosity :/
[Answer]
## R - 94 bytes
```
for(i in 0:100){cat('\rLoading',c('-','\\','|','/')[i%%4+1],i,'%');Sys.sleep(sample(750,1)/1e3)}
```
Really nice that `sample(750,1) == sample(1:750,1)`.
[Answer]
# HTML + JS (ES6), 16 + 87 = 103 bytes
```
(f=_=>a.innerHTML='\\|/-'[i++%4]+` ${i<100&&setTimeout(f,Math.random()*750),i} %`)(i=0)
```
```
loading <a id=a>
```
[Answer]
# PHP, ~~66~~ 79 bytes
```
for($i=-1;++$i<101;usleep(rand(1,75e4)))echo"\rloading ","-\\|/"[$i%4]," $i %";
```
Unfortunately I had to assign $i in order to get it to print '0'.  
Use like:
```
php -r 'for($i=-1;++$i<101;usleep(rand(1,75e4)))echo"\rloading ","-\\|/"[$i%4]," $i %";'
```
Edits: thanks to Titus confirming exactly what's allowed with Mukul Kumar we can save 3 bytes with a less restricted range, but not all 9 bytes with an unrestricted range. Thanks also for pointing out that I forgot the cycling character and providing a simple solution to do it.
[Answer]
# [Noodel](https://tkellehe.github.io/noodel/), noncompeting 40 [bytes](https://tkellehe.github.io/noodel/docs/code_page.html)
Just going back through old challenges (as in challenges that were made before *Noodel*) and competing with *Noodel* to find where it is weak.
```
Loading¤”ḋḟƇḣ⁺s¤ṡ⁺Ḷ101ạ¤%ɱṠĖ²⁺Çṛ749⁺1ḍ€Ḃ
```
If final output does not matter, then can save 2 bytes.
```
Loading¤”ḋḟƇḣ⁺s¤ṡ⁺Ḷ101ạ¤%ɱṠĖ²⁺Çṛ749⁺1ḍ
```
*Noodel* pushes the top of the stack to the screen at the end of the program so by adding the `€Ḃ` it prevents that from happening.
[Try it:)](https://tkellehe.github.io/noodel/editor.html?code=Loading%C2%A4%E2%80%9D%E1%B8%8B%E1%B8%9F%C6%87%E1%B8%A3%E2%81%BAs%C2%A4%E1%B9%A1%E2%81%BA%E1%B8%B6101%E1%BA%A1%C2%A4%25%C9%B1%E1%B9%A0%C4%96%C2%B2%E2%81%BA%C3%87%E1%B9%9B749%E2%81%BA1%E1%B8%8D%E2%82%AC%E1%B8%82&input=&run=true)
### How It Works
```
Loading¤”ḋḟƇḣ⁺s¤ṡ⁺Ḷ101ạ¤%ɱṠĖ²⁺Çṛ749⁺1ḍ€Ḃ # Main Noodel script.
Loading¤”ḋḟƇḣ⁺s¤ṡ⁺                       # Creates the array ["Loading¤-¤", "Loading¤\¤", "Loading¤|¤", "Loading¤/¤"]
Loading¤                                 # Pushes the string "Loading¤"
        ”Ƈḟḋḣ                            # Pushes the array ["-", "\", "|", "/"]
             ⁺s                          # Concats "Loading¤" to each element in the array by prepending.
               ¤                         # Pushes a "¤" onto the stack.
                ṡ                        # Pushes
                 ⁺
                  Ḷ101ạ¤%ɱṠĖ²⁺Çṛ749⁺1ḍ   # Main loop that creates the animation.
                  Ḷ101                   # Loop the following code 101 times.
                      ạ                  # Pushes on a copy of the next animation element from the array.
                       ¤%                # Pushes the string "¤%"
                         ɱ               # Pushes on the current count of the number of times that have looped (zero based).
                          Ṡ              # Swaps the two items at the bottom of the stack.
                           Ė             # Pushes the item at the bottom of the stack to the top (which will be the string selected from the array).
                            ²⁺           # Concat twice appending the loop count then the string "¤%" to the string selected from the array.
                              Ç          # Pops the string off of the stack, clears the screen, then prints the string.
                               ṛ749      # Randomly generate an integer from 0 to 749.
                                   ⁺1    # Increment the random number producing a random number from 1 - 750.
                                     ḍ   # Pop off the stack and delay for that number of milliseconds.
                                      €Ḃ # Ends the loop and prevents anything else being displayed.
                                      €  # Ends the loop (new line could be used as well)
                                       Ḃ # Destroys the current stack therein, nothing gets pushed to the screen at the end of the program.
```
```
<div id="noodel" code="Loading¤”ḋḟƇḣ⁺s¤ṡ⁺Ḷ101ạ¤%ɱṠĖ²⁺Çṛ749⁺1ḍ€Ḃ" input="" cols="14" rows="2"></div>
<script src="https://tkellehe.github.io/noodel/noodel-latest.js"></script>
<script src="https://tkellehe.github.io/noodel/ppcg.min.js"></script>
```
[Answer]
## C ~~126~~ 121 bytes
```
f(){i=0;char c[]="/-\\|";for(;i<101;i++){printf("\rloading %c %d %% ",c[i%4],i);fflush(stdout);usleep(1000*(rand()%75));}
```
Ungolfed version:
```
 void f()
 {
  int i=0;
  char c[]="/-\\|";
  for(;i<101;i++)
  {
    printf("\rloading %c %d %% ",c[i%4], i);
    fflush(stdout);
    usleep(1000*(rand()%75));  
  }
 } 
```
@Carcigenicate @ Mukul Kumar Did not read between the lines there, Thanks! :)
[Answer]
# **MATLAB, 108 bytes**
```
function k;for i=0:100;a='-\|/';pause(rand*.749+.001);clc;['loading ' a(mod(i,3)+1) ' ' num2str(i) ' %']
end
```
[Answer]
# Octave, ~~122~~ ~~120~~ ~~119~~ 108 bytes
I misread the challenge and created an infinite loader that restarted at 0 once it passed 100. Making it into a one time only loader:
```
a='\|/-';for i=0:100;clc;disp(['Loading ',a(1),' ',num2str(i),' %']);a=a([2:4,1]);pause(0.749*rand+.001);end
```
Circulating `a`, `a=a([2:4,1])` was flawr's idea [here](https://codegolf.stackexchange.com/a/101293/31516). Also, saved 2 bytes by skipping the parentheses after `rand` thanks to MattWH.
[Answer]
# ForceLang, 250 bytes
Noncompeting, requires language features which postdate the question
```
def D def
D w io.write
D l e+"loading"+s
D z string.char 8
D s string.char 32
D d datetime.wait 750.mult random.rand()
D e z.repeat 24
D n set i 1+i
D k s+n+s+"%"
set i -1
label 1
w l+"-"+k
if i=100
exit()
d
w l+"\"+k
d
w l+"|"+k
d
w l+"/"+k
d
goto 1
```
I should probably fix some bugs related to string literal parsing soon.
[Answer]
## Racket 110 bytes
```
(for((i 101))(printf"Loading ~a ~a % ~n"(list-ref'("-" "\\" "|" "/")(modulo i 4))i)(sleep(/(random 750)1000)))
```
Ungolfed: 
```
(define(f)
  (for ((i 101))
    (printf "Loading ~a ~a % ~n" (list-ref '("-" "\\" "|" "/") (modulo i 4)) i)
    (sleep (/(random 750)1000))))
```
Testing: 
```
(f)
```
Output: 
[![enter image description here](https://i.stack.imgur.com/vrjc7.gif)](https://i.stack.imgur.com/vrjc7.gif)
(This gif file is showing slower display than actual)
[Answer]
# 107 75 Ruby
*-32 thanks to manatwork*
**Normal**
```
i=0
(0..100).each{|c|
system'clear'
puts"loading #{'\|/-'[i=-~i%4]} #{c} %"
sleep rand*(0.750-0.01)+0.01
}
```
**Golfed**
```
101.times{|c|$><<"\rloading #{'-\|/'[c%4]} #{c} %";sleep rand*0.749+0.001}
```
[Answer]
### Python 3, 149 bytes
```
import time,random;f=0;n=0
while n<=100:
 print("Loading...","|/-\\"[f],n,"%",end="\r");f+=1
 if f>=3:f=0
 n+=1
 time.sleep(random.uniform(.25,.75))
```
Similar to Loading... Forever, but I did have to edit my answer from there a lot.
[Answer]
# TI-Basic, 80 bytes
```
For(I,0,100
For(A,0,randE2
End
Text(0,0,"loading "+sub("-\|/",1+fPart(I/4),1)+" ",I," %
End
```
The randomness comes from the `For(` loop (E is scientific E token) and since TI-Basic is interpreted there is also automatically some overhead. Remember that in TI-Basic, lowercase letters and some less common ASCII symbols are two bytes each (so specifically for this program, `l o a d i n g sub( \ | %` are the two-byte tokens
[Answer]
# Clojure, 109 bytes
```
(doseq[[c i](map vector(cycle"\\|/-")(range 101))](print"\rloading"c i\%)(flush)(Thread/sleep(rand-int 751)))
```
Loops over a list of the range of numbers from 0 to 100, zipped with an infinite list of `"\|/-"` repeating forever.
```
; (map vector...) is how you zip in Clojure
;  All arguments after the first to map are lists. The function is expected to
;  take as many arguments as there are lists. vector is var-arg.
(doseq [[c i] (map vector (cycle "\\|/-") (range 101))]
  ; \r to erase the old line
  (println "\rloading" c i \%)
  (Thread/sleep (rand-int 751)))
```
[Answer]
# tcl, 116
```
set i 0;time {lmap c {- \\ | /} {puts -nonewline stderr "\rloading $c $i%";after [expr int(187*rand())]};incr i} 100
```
Playable in <http://www.tutorialspoint.com/execute_tcl_online.php?PID=0Bw_CjBb95KQMOXoybnVSOVJEU00>
[Answer]
## Visual Basic, 371 Bytes
```
module m
sub main()
Dim s as Object
for i as Integer=0 to 100
Select Case new System.Random().next(0,9)
Case 0
s=1
Case 1
s=2
Case 2
s=5
Case 3
s=10
Case 4
s=15
Case 5
s=20
Case 6
s=25
Case 7
s=50
Case 8
s=500
End Select
Console.SetCursorPosition(0,0)
console.write("loading "+"-\|/"(i mod 4)+" "+i.tostring+" %")
system.threading.thread.sleep(s)
next
end sub
end module
```
# Expanded:
```
module m
    sub main()
        Dim s as Object
        for i as Integer=0 to 100
            Select Case new System.Random().next(0,9)
                Case 0
                s=1
                Case 1
                s=2
                Case 2
                s=5
                Case 3
                s=10
                Case 4
                s=15
                Case 5
                s=20
                Case 6
                s=25
                Case 7
                s=50
                Case 8
                s=500
            End Select
            Console.SetCursorPosition(0,0)
            console.write("loading " + "-\|/"(i mod 4) + " " + i.tostring + " %")
            system.threading.thread.sleep(s)
        next
    end sub
end module
```
[Answer]
# Java 8, 130 bytes
```
()->{for(int n=0;n<101;Thread.sleep((long)(1+Math.random()*750)))System.out.print("\rloading "+"-\\|/".charAt(n%4)+" "+n+++" %");}
```
**Explanation:**
```
()->{                           // Method without parameter nor return-type
  for(int n=0;n<101;            //  Loop from 0 to 100
      Thread.sleep((long)(1+Math.random()*750)))
                                //   And sleep randomly 1-750 ms 
    System.out.print(           //   Print:
      "\r                       //    Reset to the start of the line
      loading "                 //    Literal "loading "
      +"-\\|/".charAt(n%4)+" "  //    + the spinner char & a space
      +n++                      //    + the number (and increase it by 1)
      +" %");                   //    + a space & '%'
                                //  End of loop (implicit / single-line body)
}                               // End of method
```
**Output gif:**
[![enter image description here](https://i.stack.imgur.com/hVAwH.gif)](https://i.stack.imgur.com/hVAwH.gif)
]