29
7
Make a fake loader just like this :
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
herems
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.
11Related – James – 2016-12-08T17:32:51.540
1I didn't think this was a duplicate. This question cannot be implemented in ><>, but can be in *><> for example. I quite liked it. – redstarcoder – 2016-12-08T21:25:10.543
1@Mego The question isn't a duplicate. The output is a little different, the runtime is completelly different and the output requires a random time instead of a fixed 250ms delay. Answers on one question can't be used on the other without heavy modification. Please, read the questions. – Ismael Miguel – 2016-12-08T21:32:05.910
8As the author of the other challenge I'll step in with the dupe debate. Although the cycling chars (
\|/-
) are the same, the answer seems to be different in that it is not infinite and involves generation of random numbers, rather than a static output. Therefore I'll say, although I initially felt copied, this doesn't look like a dupe to me. – FlipTack – 2016-12-08T22:12:48.670@flp.tkc this idea came from many places combined like I saw
-\|/
in some games.And I was inspired from console installation programs. – Mukul Kumar – 2016-12-09T02:50:20.627Are 1..750ms an exact, a maximal or a minimal range of numbers that we should generate for the delay? – Titus – 2016-12-09T17:49:21.403
@Titus If you know c-related languages then this should clarify your doubt
rand ()%750+1
. – Mukul Kumar – 2016-12-09T17:59:08.347My issue is that in PHP
rand()
returns an integer; and you cannot delay by milliseconds: it´s either seconds or microseconds. So: would [1..750k] microseconds be ok? or [1..1mill] microseconds? – Titus – 2016-12-09T18:14:23.933@Titus Sure that's ok
[1,750K]
is acceptable. And a v.important point has been clarified i.e. the time-delay is in milliseconds. – Mukul Kumar – 2016-12-09T18:23:02.983