Challenge:

In a hypothetical scenario, the countdown timer for a race has random intervals between the counts, to prevent premature starting, e.g.

3 (0.82 seconds pass), 2 (0.67 seconds pass), 1


nothing

Output:

Write a program (or function) that prints the 3 numbers with a random time interval from 0.50 seconds to 1 second between each count.

Note:

• The program must output each number (3 , 2 , 1) with the random (any number between 0.50 and 1 to the hundredths; no hard-coding) time interval between each. The precision of the random interval must go out to the hundreds (e.g: 0.52). You are not required to output the interval, only the count.
• As @JoKing clarified, I mean uniformly random (you can use the pseudo-random generator of your language.
• As many people have clarified, I really mean any 2-decimal number between 0.5 and 1. (0.50, 0.51, etc, all the way to 0.98, 0.99, 1)

This is , so the program with the lowest byte count wins.

• Hi LordColus, and welcome to PPCG! This seems like a good first challenge. For future challenges, we recommend going through the sandbox first to iron out all the details. – Mnemonic May 1 '18 at 3:05
• @LordColus : I improved the original statement and couple of other edits , take a look and approve if you want. – Muhammad Salman May 1 '18 at 14:43
• As I said in a previous comment that has been deleted, specifying "uniformly random" is fine if you are not too stringent with precision. As it stands now, the pause times must be uniform with precision of two decimals (or is it at least two decimals?). Does that mean the distribution should be uniform on the set 0.5, 0.51, 0.52, ..., 1, or can it be any floating point (possibly with more than two decimals) beween 0.5 and 1? – Luis Mendo May 2 '18 at 10:07
• Does my most recent edit clear it up? – LordColus May 2 '18 at 12:02
• @mbomb007 Same... why did this get closed again? It's basically count from 3 to 1 with two .50-1.00 second waits in between. It's really not complicated. – Magic Octopus Urn May 2 '18 at 17:01

05AB1E, 12 bytes

3LRε=₄D;ŸΩ.W


Try it online!

3LR          # Push [3,2,1]
ε         # For each...
=        # Print it.
₄       # Push 1000.
D      # Duplicate top (1000).
;     # Divided by 2 (500).
Ÿ    # Range from b to a ([1000 .. 500]).
Ω   # Random pick.
.W # Wait X ms.


Try it with debug enabled: Try it online!

SmileBASIC, 64 62 bytes

?3M?2M?1DEF M
M=MILLISEC
WHILE MILLISEC<M+500+RND(501)WEND
END


Unfortunately I can't use WAIT since that only supports intervals of 1/60 of a second (anything less isn't normally useful since input/output only update once per frame)

This requires adjustment depending on the speed of the system it's running on, so it might not be valid (46 bytes):

?3M?2M?1DEF M
FOR I=-66E4-RND(66E4)TO.NEXT
END


Invalid WAIT version (36 bytes):

?3WAIT 30+RND(30)?2WAIT 30+RND(30)?1


R, 46 44 bytes

for an actual countdown:

for(i in 3:1){cat(i)
Sys.sleep(runif(1,.5))}


Try it online!

printing interval as I initially misunderstood the challenge (46 bytes) Thanks Giuseppe for saving 2 chars.

for(i in 3:1)cat(i,format(runif(1,.5),,2)," ")


Try it online!

• I believe runif() by default has the left and right endpoints as 0 and 1 respectively, so runif(1,.5) should work the same for -2 bytes in both. – Giuseppe May 1 '18 at 19:45
• Good catch thanks @Giuseppe. – JayCe May 1 '18 at 20:01

Python 2, 58 bytes

from time import*
for a in'321':print a;sleep(1-time()%.5)


Try it online!

I created a very simple random number generator that takes the seed time (as many people do).

Improvements

• 1-time()%.5 should do the trick. (You need [3,2,1] by the way) – Jonathan Allan May 1 '18 at 20:38
• Also for a in'321' saves another two – Jonathan Allan May 1 '18 at 20:50
• @JonathanAllan Very good point, updated. – Neil May 1 '18 at 22:21
• This sleeps once before the countdown too. I think you need the print statement before the sleep. – Magic Octopus Urn May 2 '18 at 17:05
• @MagicOctopusUrn Agreed, updated. – Neil May 3 '18 at 3:56

APL+WIN, 37 bytes

3⋄r←⎕dl ↑n←.49+.01×2?51⋄2⋄r←⎕dl 1↓n⋄1


Java 8, 86 bytes

v->{for(int i=0;++i<4;Thread.sleep((int)(Math.random()*500+500)))System.out.print(i);}


Prints without delimiter. If that is not allowed it's +2 bytes by changing print to println (new-line delimiter).

Explanation:

v->{                        // Method with empty unused parameter and no return-type
for(int i=0;++i<4;        //  Loop in range [1,4)
//    After every iteration: sleep for [500, 1000) ms randomly
System.out.print(i);}  //   Print the current number


Python 3, 122 bytes

import random as r,time
def w():time.sleep(abs(r.random()-.5)+.5)
print(3,end="");w();print(", 2",end="");w();print(", 1")


Try it online!

JavaScript (Node.js), 7565 60 bytes

• thanks to @Shaggy for reducing by 10 bytes
• thanks to @Kevin Cruijssen for reducing by 5 bytes
f=(i=3)=>i&&setTimeout(f,Math.random()*500+500,i-1,alert(i))


Try it online!

• 55 bytes – Shaggy May 1 '18 at 21:42
• @Shaggy will it really be random if you're using Date ? (for the second time the random occured) – DanielIndie May 2 '18 at 3:27
• Why *1000%500+500? You can just use *500+500. – Kevin Cruijssen May 2 '18 at 7:08
• With the updates to the spec, it probably won't be random enough but it might be worth asking for clarification. – Shaggy May 2 '18 at 9:27

Perl 5, 39 bytes

Gradually tweaked down to 39 bytes, thanks to @jonathan-allan + @xcali.

say-$_+select$a,$a,$a,1-rand.5for-3..-1


Try it online!

• would 1-rand(.5) work? – Jonathan Allan May 1 '18 at 20:56
• Good idea. Can then use 1-rand.5 too. – steve May 1 '18 at 21:00
• Cut four more bytes by removing the parens and changing the counter to be negative. Try it online! – Xcali May 2 '18 at 17:07

Chip-wingjj, 33 bytes

0123456e7f s
???????p*9S!ZZZtaABb


Try it online!

In Chip, we cannot wait for exactly 1/100 of a second, but we can wait for 1/256 of a second, so we use that here.

p, when asked, will pause execution for the stack head (one byte) * 1/256 seconds. On each cycle, we always set the high bit of the stack (128/256) and set all other stack bits randomly (with the ?'s). This gives an even distribution between 0.50 and 1.00 seconds.

Some of the args, -w and -gjj, specify that the input, instead of using stdin, should be a countdown from 0xFF to 0x00 (then wrapping). We use this to provide the low two bits for counting down. All other output bits remain constant (at the value corresponding to ASCII 0).

Finally, once we are done, we terminate the program with t, preventing a pause after the last number.

[GAWK], 57 bytes

BEGIN{while(a++<2){print 4-a;sleep(rand()/2+0.5)}print 1}


Try it online!