[Question]
  [
This challenge is inspired by [xkcd](https://xkcd.com/612/):
[![enter image description here](https://i.stack.imgur.com/rDl1T.png/ "They could say \"the connection is probably lost,\" but it's more fun to do naive time-averaging to give you hope that if you wait around for 1,163 hours, it will finally finish.")](https://i.stack.imgur.com/rDl1T.png/ "They could say \"the connection is probably lost,\" but it's more fun to do naive time-averaging to give you hope that if you wait around for 1,163 hours, it will finally finish.")
## Challenge:
You'll simulate the copying a large file (1 Gigabyte). The transfer rate will vary between 10 kB/second to 100 MB/second.
Your task is to output the time remaining of the file transfer. The output should look like:
```
Time remaining: 03:12    (meaning it's 3 minutes and 12 seconds left)
Time remaining: 123:12   (meaning it's 2 hours, 3 minutes and 12 seconds left)
Time remaining: 02:03:12 (optional output, meaning the same as above)
```
Leading zeros need not be displayed for minutes and hours (optional), but must be shown for seconds. Showing the time remaining using only seconds is not OK.
**The file transfer:**
* The transfer rate will start at 10 MB/second.
* Every second, there will be a 30% chance that the transfer rate will change
* The new transfer rate should be picked randomly (uniform distribution) in the range `[10 kB/s, 100 MB/s]`, in steps of 10 kB/s.
**Note: You don't need to actually copy a file.**
You may choose to use: `1 GB = 1000 MB, 1 MB = 1000 kB, 1 kB = 1000 B`, or `1 GB = 1024 MB, 1 MB = 1024 kB, 1 kB = 1024 B`. 
**Output:**
* You start at `01:40`, not `01:39`.
* You display the time after the transfer rate changes, but before anything is transferred at that rate
* The seconds should be displayed as integers, not decimals. It's optional to round up/down/closest.
* You should clear the screen every second, unless that's impossible in your language.
* The output should be constant: `Time remaining: 00:00` when the file transfer is over.
**Example:**
I have rounded up all decimal seconds. 
Assume the lines below are shown with 1 second in between, and the screen is cleared between each one:
```
Time remaining: 01:40  (Transfer rate: 10 MB/s)
Time remaining: 01:39      1 GB - 10 MB
Time remaining: 01:38      1 GB - 2*10 MB
Time remaining: 01:37      1 GB - 3*10 MB
Time remaining: 01:28:54   1 GB - 4*10 MB  (TR: 180 kB/s)
Time remaining: 01:28:53   1 GB - 4*10 MB - 180 kB
Time remaining: 01:28:52   1 GB - 4*10 MB - 2*180 kB  
Time remaining: 00:13      1 GB - 4*10 MB - 3*180 kB  (TR: 75 MB/s)
Time remaining: 00:12      1 GB - 4*10 MB - 3*180 kB - 75 MB
Time remaining: 00:11      1 GB - 4*10 MB - 3*180 kB - 2*75 MB
Time remaining: 00:10      1 GB - 4*10 MB - 3*180 kB - 3*75 MB
Time remaining: 00:09      1 GB - 4*10 MB - 3*180 kB - 4*75 MB
Time remaining: 00:08      1 GB - 4*10 MB - 3*180 kB - 5*75 MB
Time remaining: 14:09:06   1 GB - 4*10 MB - 3*180 kB - 6*75 MB  (TR: 10 kB/s)
Time remaining: 14:09:05   1 GB - 4*10 MB - 3*180 kB - 6*75 MB - 10 kB
Time remaining: 00:06      1 GB - 4*10 MB - 3*180 kB - 6*75 MB - 20 kB  (TR: 88.110 MB/s)
Time remaining: 00:05
Time remaining: 00:04
Time remaining: 00:03
Time remaining: 00:02
Time remaining: 00:01
Time remaining: 00:00     <- Transfer is finished. Display this.
```
  
[Answer]
# Pyth - ~~70~~ 68 bytes
```
K^T5J^T3W>KZ%." r3úBTêî¢¤;¥
í".D/KJ60=J?<OT3O^T4J=-KJ.d1.
```
[Try it online without sleeps](http://pyth.herokuapp.com/?code=K%5ET5J%5ET3W%3EKZ%25.%22+r%04%1B%133%C2%92%17%C3%BABT%C3%AA%C2%9A%C3%AE%C2%A2%C2%97%0F%C2%A4%3B%C2%A5%0A%01%C3%AD%05%14%22.D%2FKJ60%3DJ%3F%3COT3O%5ET4J%3D-KJ&debug=0).
[Answer]
# [PowerShell](https://github.com/PowerShell/PowerShell), ~~190~~ ~~215~~ 187 bytes
```
($t="Time remaining: ")+"00:01:42";for($f,$r=1gb,10mb;$f-gt0;$f-=$r){if((Random 10)-lt3){$r=(Random -mi 1kb -ma (10mb+1))*10}$t+[Timespan]::FromSeconds([int]($f/$r));sleep 1}$t+"00:00:00"
```
[Try it online!](https://tio.run/nexus/powershell#NU69CsMgGHwVEQdtIvVrOxmy9gHabiGDSUwqjRqMW@hjd061UDg4OO5vpyTW@GGsRkFbZZxxk0SYFVgIKUBeTrgafaBkLEmoYepKELaryMinKDLVJLDNjJTelBu8RSAYn@OZbcn@17g1CF5dYoVozhfA2AHEm8Siydvrolwr5TV4e9e9d8NKG@Nim2aPqZ9V66z1giAHfscy8L5/nOe96p/6Cw "PowerShell – TIO Nexus") (TIO doesn't support clearing screen between lines)
Sets our initial `$f`ile size and our initial transfer `$r`ate to `1gb` and `10mb`/s, respectively. Then, so long as we still have `$f`ile remaining, we loop.
Inside the loop, the `if` selects a number from `0` to `9` inclusive, and if it's 0, 1, or 2 (i.e., 30% of the time), we change the rate. This picks a random integer between `1kb` and `10mb` then that's multiplied by `10` to get our step count.
We then leverage the `FromSeconds` [static method](https://technet.microsoft.com/en-us/library/system.timespan.fromseconds(v=VS.85).aspx) from the `TimeSpan` .NET library to construct the time remaining. The output format of that call exactly matches the challenge requirements, so no need for additional formatting.
*(Saved a bunch thanks to @ConnorLSW)*
[Answer]
# Ruby, ~~116~~ 110 bytes
[Try it online, except repl.it reads `\r` as a newline and also can't use `$><<` so it's replaced with its 5-byte equivalent, `print`.](https://repl.it/F56D)
Shoutout to JonasWielicki for the initial idea of using `\r` to reset the line.
```
f=1e5;r=1e3;(k=f/r=rand<0.3?1+rand(1e4):r;$><<"\rTime remaining: %02d:%02d"%[k/60,k%60];f-=r;sleep 1)while f>0
```
This version is untested on Windows, but works on Unix.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 78 bytes
*Thanks to [@Maltysen](https://codegolf.stackexchange.com/users/31343/maltysen) and [@DigitalTrauma](https://codegolf.stackexchange.com/users/11259/digital-trauma) for corrections.*
```
1e5 1e3`XK10&XxyXIy/t0>*12L/'MM:SS'XO'Time remaining: 'whD-r.3<?1e4Yr}K]I0>]xx
```
Try it at [MATL Online!](https://matl.io/?code=1e5+1e3%60XK10%26XxyXIy%2Ft0%3E%2a12L%2F%27MM%3ASS%27XO%27Time+remaining%3A+%27whD-r.3%3C%3F1e4Yr%7DK%5DI0%3E%5Dxx&inputs=&version=19.7.4) (you may need to press "Run" several times if it doesn't initially work).
The online interpreter times out after 30 seconds. You may want to change `10` (pause time in tenths of second) to something smaller [such as `3`](https://matl.io/?code=1e5+1e3%60XK3%26XxyXIy%2Ft0%3E%2a12L%2F%27MM%3ASS%27XO%27Time+remaining%3A+%27whD-r.3%3C%3F1e4Yr%7DK%5DI0%3E%5Dxx&inputs=&version=19.7.4) in order to increase speed of display
### Explanation
```
1e5                  % Push 1e5: file size in 10-kB units
1e3                  % Push 1e3: initial rate in 10-kB/s units
`                    % Do...while
  XK                 %   Copy current rate into clipboard K (doesn't consume it)
  10&Xx              %   Wait 1 second and clear screen
  y                  %   Duplicate current file size onto the top of the stack
  XI                 %   Copy it to clipboard I (doesn't consume it)
  y                  %   Duplicate current rate onto the top of the stack
  /                  %   Divide. This gives the estimated remaining time in seconds
                     %   It may be negative in the last iteration, because the
                     %   "remaining" file size may have become negative
  t0>*               %   If negative, convert to 0
  12L/               %   Push 86400 and divide, to convert from seconds to days
  'MM:SS'XO          %   Format as a MM:SS string, rounding down
  'Time remaining: ' %   Push this string
  wh                 %   Swap, concatenate
  D                  %   Display
  -                  %   Subtract. This gives the new remaining file size
  r                  %   Push random number uniformly distributed in (0,1)
  .3<                %   Is it less than 0.3?
  ?                  %   If so
    1e4Yr            %     Random integer between 1 and 1e4. This is the new rate 
                     %     in 10-kB/s units
  }                  %   Else
    K                %     Push rate that was copied into clipboard K
  ]                  %   End
  I                  %   Push previous remaining file size from clipboard I
  0>                 %   Is it positive?
]                    % End. If top of the stack is true: next iteration
xx                   % Delete the two numbers that are on the stack
```
[Answer]
# Bash + common utils, 117
Straightforward implementation. A few bytes saved by dividing out by 10000:
```
for((b=10**5,r=1000;b>0;r=RANDOM%10<3?RANDOM%10000+1:r,b-=r));{
clear
date -ud@$[b/r] "+Time remaining: %T"
sleep 1
}
```
[Try it online](https://tio.run/nexus/bash#@5@WX6ShkWRraKClZapTBKQNDKyT7Aysi2yDHP1c/H1VDQ1sjO3hbCDQNrQq0knStS3S1LSu5krOSU0s4kpJLElV0C1NcVCJTtIvilVQ0g7JzE1VKErNTczMy8xLt1JQDVHiKs5JTS1QMOCq/f//a16@bnJickYqAA). Using `sleep 0` on the TIO so you don't have to wait. `clear` doesn't work on TIO.
[Answer]
# JavaScript (ES6), 162 bytes
Shows minutes as is with padded seconds (floored)
E.g., `123:45`
```
t=1e5
s=1e3
setInterval(c=>c.log(`Time remaining: ${c.clear(d=t/s),d/60|0}:`+`0${t-=s>t?t:s,r=Math.random,s=r()<0.3?1+r()*1e4|0:s,d%60|0}`.slice(-2)),1e3,console)
```
[Answer]
# Python 3.6 (~~212~~ 203 bytes)
```
from random import*
import time,datetime
r=1e7
d=1e9
while 1:
 print(f"\x1b[KTime remaining: {datetime.timedelta(seconds=d//r)}",end="\r");d=max(0,d-r);time.sleep(1)
 if random()>.7:r=randint(1,1e4)*1e4
```
Pretty straightforward, I think. Erases the line using ANSI escape sequence and `K` command.
* Saved 9 bytes thanks to [@ValueInk](https://codegolf.stackexchange.com/questions/108976/copy-a-file-windows-style/109026?noredirect=1#comment265544_109026)
[Answer]
## Batch, 193 bytes
```
@set/ap=10000,s=p*10,r=p/10
:l
@set/at=s/r,m=t/60,n=t%%60+100,s-=r
@cls
@echo Time remaining: %m%:%n:~1%
@timeout/t>nul 1
@if %random:~-1% lss 3 set/ar=%random%%%p+1
@if %t% gtr 0 goto l
```
Note: Slight bias towards rates of 27.68 MB/s or less.
[Answer]
## C ~~184~~ ~~171~~ 155 bytes
```
f(){i,j=0,r=1e7;for(i=1e9;i>0;i-=r){j=i/r;printf("Time remaining: %02d:%02d:%02d\r",j/3600,(j/60)%60,j%60);sleep(1);if(rand()%10<3)r=(rand()%10000)*1e4;}}
```
I hope this qualifies.
Ungolfed version:
```
void f()
{
    int j=0;
    float rate=1e7; 
    for(int size=1e9;i>0; size-=rate)
    {     
       j=size/rate;      
       printf("Time remaining: %02d:%02d:%02d\r",j/3600,(j/60)%60,j%60);
       sleep(1);
       if(rand()%10<3)
          rate=(rand()%10000)*1e4;          
   }
}
```
Explanation: In the golfed version `i` corresponds to `size` in ungolfed version and `r` is `rate` in ungolfed version. `j` stores the time remaining in seconds.
* I have 10^9 bytes to copy. I start copying at the rate of 10 Megabytes/second,
* If the probablity is less than 30% , change the rate (from 10 kilobytes to 100 Megabytes per second)
@ValueInk Thanks for saving 13 bytes.
@nmjcman101 Thanks for saving 16 bytes.
]