39
\$\begingroup\$

Introduction

The game Minecraft has a 1 in 10000 chance of showing "Minceraft" instead of "Minecraft" on the title screen.

Your challenge

Your challenge is to code a function or program that takes no input, and on average 1 of 10000 times, returns "Minceraft" and the rest of the time returns "Minecraft".

Scoring

This is , shortest wins!

\$\endgroup\$
9
  • \$\begingroup\$ All solutions so far will not satisfy the challenge as stated (they might, but highly unlikely). It has in fact been misstated - it is correct in the introduction, but the challenge asks for something different \$\endgroup\$ – jonrandy Apr 25 at 11:10
  • \$\begingroup\$ @jonrandy What do you mean? \$\endgroup\$ – A username Apr 25 at 11:12
  • 1
    \$\begingroup\$ The introduction talks about a 1 in 10000 chance, whereas the challenge asks for a function/program that returns "Minceraft" EXACTLY once and "Minecraft" the rest of the time. This would be achieved with a loop. The solutions below are doing what is stated in the introduction, which is different \$\endgroup\$ – jonrandy Apr 25 at 11:15
  • 8
    \$\begingroup\$ Suggest edit: "on average 1 out of 10000 times", assuming this is the intention, to satisfy nitpickers... \$\endgroup\$ – Dominic van Essen Apr 25 at 11:16
  • 10
    \$\begingroup\$ how precisly does it have to be 1/10000 ? multiple answers have 1/10001 for example \$\endgroup\$ – MarcMush Apr 26 at 14:01

54 Answers 54

37
\$\begingroup\$

Minecraft, 358 293 277 276 bytes

Implementing Minceraft in Minecraft

Should be run as a set of commands in game. Should be run on a fresh superflat (redstone ready) world. Byte count is the amount of characters you need to type, including newlines.

/scoreboard objectives add s dummy
/summon bat
/execute as @e[type=bat] store result score o s run data get entity @s UUID[1]
/scoreboard players set c s 2147054151
/execute if score o s < c s run tellraw @s "Minecraft"
/execute if score o s >= c s run tellraw @s "Minceraft"

The UUID of an entity is (mostly) randomly generated and stored as four signed 32 bit integers. One of the integers is compared with 2147054151 which is one ten thousandth of the way between 2^31 and -2^31.

Previous solution because it was so high effort and I'm not deleting it:

Minecraft, 293 bytes

/scoreboard objectives add s dummy
/summon horse
/execute as @e[type=horse] store result score o s run data get entity @s Attributes[1].Base 100000
/scoreboard players set c s 11883
/execute if score o s >= c s run tellraw @s "Minecraft"
/execute if score o s < c s run tellraw @s "Minceraft"

How does it work?

In Minecraft, there are only a limited amount of sources of reliable randomness usable in commands. In Minecraft Functions you can use predicates with specific random chances, but that requires multiple files and submitting that as a zipped data pack would be at least 1 KB.

To avoid this and have it run solely from commands a player can type in, this uses horses as a random source. When a horse is spawned, it is assigned a random speed between 0.1125 and 0.3375 (the units are arbitrary). The random speed calculation is as follows:

$$0.25(0.45 + 0.3x + 0.3y + 0.3z)$$

Where x, y, and z are uniform independent random variables [0, 1). If you find the cumulative density function by convolving the distribution functions (to get the PDF) and then integrating, you will end up with the following piecewise function:

$$ f(x)=\begin{cases}-\frac{9}{16}+15x-\frac{400x^{2}}{3}+\frac{32000x^{3}}{81}&\frac{9}{80}\le x<\frac{3}{16}\\ \frac{29}{4}-110x+\frac{1600x^{2}}{3}-\frac{64000x^{3}}{81}&\frac{3}{16}\le x<\frac{21}{80}\\ -\frac{227}{16}+135x-400x^{2}+\frac{32000x^{3}}{81}&\frac{21}{80}\le x<\frac{27}{80} \end{cases} $$

We need to find the horse speed where the probability of a horse with that speed or lower spawning is one in ten thousand or 0.0001. This can be done by solving the first equation:

$$-\frac{9}{16}+15x-\frac{400x^{2}}{3}+\frac{32000x^{3}}{81} = 0.0001\\ f^{-1}(0.0001)\simeq0.11882574$$

This results in the horse speed being multiplied by 100,000 (because scoreboard values must be integers) and compared with 11883 in the code.

The precision is currently 1.00202 in 10,000. Two bytes can be added or removed for approximately each order of magnitude required. Two additional bytes will make it 1.00012 in 10,000.

\$\endgroup\$
13
  • \$\begingroup\$ I see no reason to run these separately over putting them all in a .mcfunction file and running that. \$\endgroup\$ – Egor Hans Apr 27 at 7:11
  • \$\begingroup\$ Minecraft datapacks require a pack.mcmeta which would make it too expensive. However, I am not certain of the consensus regarding Minecraft commands. \$\endgroup\$ – Okx Apr 27 at 7:20
  • 2
    \$\begingroup\$ I'd argue the pack.mcmeta doesn't count towards the size, only the .mcfunction file. After all, codegolf.stackexchange.com/a/224450/62991 doesn't count the time module's size either. \$\endgroup\$ – Egor Hans Apr 27 at 7:23
  • \$\begingroup\$ This is also a "full program" (as much as you can get a full program in Minecraft) compared to a function as you cannot reliably run it multiple times in one world. \$\endgroup\$ – Okx Apr 27 at 16:23
  • \$\begingroup\$ Aww, I was hoping you built a giant Redstone computer in the game to run this program, would be hard to give that a byte-count though. Maybe count in number of blocks? \$\endgroup\$ – Darrel Hoffman Apr 27 at 18:08
10
\$\begingroup\$

Python 3, 63 59 bytes

My idea was to use the time module as a PRNG since the challenge stated

on average 1 of 10000 times, returns "Minceraft" and the rest of the time returns "Minecraft"

and taking the time mod 10000 does exactly that.

Thanks @movatica for -4

import time
print(f"Min{'ceec'[time.time()%1e4>1::2]}raft")

Try it online!

Alternative, also 59 bytes:

import time
print("Min%sraft"%"ceec"[time.time()%1e4>1::2])

Try it online!

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Right, fixed. :) \$\endgroup\$ – EnderShadow8 Apr 26 at 13:40
  • 1
    \$\begingroup\$ you should add a tio link, so that it's easier for other people to test your code \$\endgroup\$ – MarcMush Apr 26 at 14:13
  • \$\begingroup\$ Can't you replace time()%1e4>1 and'ec'or'ce' with ['ec','ce'][time()%1e4>1] for -1? \$\endgroup\$ – Command Master Apr 26 at 14:40
  • \$\begingroup\$ 61 bytes \$\endgroup\$ – Command Master Apr 26 at 15:01
  • 1
    \$\begingroup\$ Welcome to codegolf! 59 bytes \$\endgroup\$ – movatica Apr 26 at 17:02
9
\$\begingroup\$

Python 3, 78 71 69 68 bytes

from random import*
f=lambda:f'Min{randint(0,1e4)and"ec"or"ce"}raft'

Try it online!

-7 bytes thanks to @Alex bries

-2 bytes thanks to @Alex bries

\$\endgroup\$
7
8
\$\begingroup\$

R, 45 44 43 bytes

`if`(runif(1)<1e-4,"Minceraft","Minecraft")

Try it online!

Boring, but shorter than any more-interesting attempt that I've tried so far...


R, 42 bytes (p=0.000101) p=1 in 10000.5

Edit: much closer to exactly 1 in 10000 (for the same bytes) thanks to Robin Ryder

`if`(rexp(1)>1e-4,"Minecraft","Minceraft")

Try it online!

Outputs "Minecraft" if an exponentially-distributed random variable is greater than 1e-4.

The exponential distribution is governed by a parameter - lambda - that defaults to 1 in the R rexp() function. This gives cumulative p(up to x)=1-exp(-lambda*x), equal to 9.9995e-05 with x=1e-4 and lamda=1, which is pretty close to 1 in 10000 (actually 1 in 10000.5).

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Alternate 43 byte solution: c("Minecraft","Minceraft")[1.0001+runif(1)] \$\endgroup\$ – Robin Ryder Apr 27 at 16:50
  • \$\begingroup\$ @RobinRyder - That's nice. I also realised we can also get almost to within 1% of the exact probability using a carefully-selected Poisson distribution, which would save 1 byte... \$\endgroup\$ – Dominic van Essen Apr 27 at 18:19
  • 1
    \$\begingroup\$ If you want an approximation of the probability, this is also 42 bytes and is more accurate, with P("Minceraft")=0.000100005. \$\endgroup\$ – Robin Ryder Apr 27 at 21:10
  • \$\begingroup\$ @RobinRyder - That's much better! Before I update the answer and credit you, can you just check my maths? Cumulative exponential distribution is 1-exp(-lambda*x), so with (default) rate=lambda=1, p(up to 1e-4)=1-exp(-0.0001)=9.9995e-05, right? In other words, pexp(1,rate=0.0001,lower.tail=T)? Or did I get something upside-down? \$\endgroup\$ – Dominic van Essen Apr 27 at 21:39
  • 1
    \$\begingroup\$ Yes, you are right - the number I gave mistakenly was the value of lambda that would have led to an exact answer. Instead, the probability is indeed 0.000099995. \$\endgroup\$ – Robin Ryder Apr 28 at 6:20
6
\$\begingroup\$

Retina, 29 bytes


ce9999*$(ec
L@$`..
Min$&raft

Try it online! Explanation:


ce9999*$(ec

Insert ce and 9999 copies of ec.

L@`..

Select one of the pairs of letters at random....

L$`
Min$&raft

... and wrap it between Min and raft.

\$\endgroup\$
6
\$\begingroup\$

Clojure, 42 bytes

#(str"Min"(if(<(rand)1e-4)"ce""ec")"raft")

Try it online!

\$\endgroup\$
6
\$\begingroup\$

C (gcc), 48 bytes

f(){printf("Min%sraft",rand()%10000?"ec":"ce");}

Try it online!

Version closer to \$\frac{1}{10000}\$

For a pseudorandomness as close to \$\frac{1}{10000}\$ as possible:

C (gcc), 79 bytes

f(){long p=0,m=1e4,i;for(i=m;i--;)p+=rand();printf("Min%sraft",p%m?"ec":"ce");}

Try it online!

\$\endgroup\$
5
  • 3
    \$\begingroup\$ Nice! Can you have 1e4 or 1e+4 in C? \$\endgroup\$ – A username Apr 25 at 12:29
  • \$\begingroup\$ @Ausername float can't be %ed \$\endgroup\$ – l4m2 Apr 25 at 12:47
  • \$\begingroup\$ @Ausername Yes C has that but it's a float and you need an integral type for a mod (%) expression. \$\endgroup\$ – Noodle9 Apr 25 at 19:20
  • 1
    \$\begingroup\$ This will not result in a 1/10000 chance if RAND_MAX is not a multiple of 10000. \$\endgroup\$ – ericw31415 Apr 26 at 4:54
  • 3
    \$\begingroup\$ @ericw31415 You might as well post this comment for every answer since they're all using PRNGs that work on scales of powers of \$2\$. Plus they're PRNGs not RNGs so there's no way to make them perfectly random. \$\endgroup\$ – Noodle9 Apr 26 at 13:25
5
\$\begingroup\$

Charcoal, 17 bytes

MinPceraft¿‽×χφec

Try it online! Link is to verbose version of code. Explanation:

Min

Print Min.

Pceraft

Print ceraft without moving the cursor.

¿‽×χφ

If a random number in the range [0..10000) is nonzero, then...

ec

... correct it to ec.

\$\endgroup\$
5
\$\begingroup\$

PowerShell, 38 bytes

"Min$(('ec','ce')[!(random 1e4)])raft"

Try it online!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I don't know Powershell, but 1000 is 1e4, not 1e5. Is that a mistake? \$\endgroup\$ – caird coinheringaahing Apr 25 at 12:58
  • \$\begingroup\$ thanks. The rule is "The game Minecraft has a 1 in 10000 chance". 10000 == 1e5 isn't it? \$\endgroup\$ – mazzy Apr 25 at 13:04
  • 1
    \$\begingroup\$ Sorry, typo in my original comment. I meant 10000, not 1000. However 10000 == 1e4: Try it online! A helpful way to remember is that the number after the 1e counts the zeros, not the digits \$\endgroup\$ – caird coinheringaahing Apr 25 at 13:05
  • \$\begingroup\$ Of course!) I'm sorry. Fixed. Thank you! \$\endgroup\$ – mazzy Apr 25 at 13:07
5
\$\begingroup\$

V (vim), 80 bytes

iMin<Esc>:r!echo $RANDOM
C<c-r>=<c-r>"%10000
<esc>:s/^0\n/ce
:s/\d\+/ec
kgJAraft

Try it online!

Generate a random no. in 0-9999, and then replace 0 with ce and anything else with ec.

\$\endgroup\$
2
  • \$\begingroup\$ i<C-r>=rand()%10000<cr><esc> is the random generator I came up with, doesn't work on TIO though sadly. \$\endgroup\$ – Citty Apr 26 at 17:34
  • \$\begingroup\$ I think rand() needs a seed but I'm not too sure of it. \$\endgroup\$ – Razetime Apr 27 at 1:40
5
\$\begingroup\$

Jelly, 18 17 bytes

“ẹ?ŀɼƲṬ`Ỵȧ»ȷ4XỊịḲ

Try it online!

Full program.

-1 byte thanks to Jonathan Allan!

How it works

“ẹ?ŀɼƲṬ`Ỵȧ»ȷ4XỊịḲ - Main link. Takes no arguments
“ẹ?ŀɼƲṬ`Ỵȧ»       - Compressed string "Minceraft Minecraft"; Call that S
           ȷ4     - 10000
             X    - Random integer between 1 and 10000
              Ị   - Is that equal to 1?
                Ḳ - Split S on spaces
               ị  - Index into the split S
\$\endgroup\$
2
  • 1
    \$\begingroup\$ A 17: “ẹ?ŀɼƲṬ`Ỵȧ»ȷ4XỊịḲ. (Also, another 18: ȷ4XỊ⁾ecṙ“¡Œ!“¡^лj.) \$\endgroup\$ – Jonathan Allan Apr 25 at 13:24
  • \$\begingroup\$ @JonathanAllan Oh, nice, thanks! (also, got to love comment markdown ಠ_ಠ) \$\endgroup\$ – caird coinheringaahing Apr 25 at 13:27
5
\$\begingroup\$

J, 28 25 bytes

'Minecraft'120&A.~0=?@1e4

Try it online!

-3 thanks to Bubbler

Note: J does not allow 0-argument functions, but this function ignores it's argument, which is the J equivalent

To see this work, change 1e4 to 2 in the TIO, which will make the letter swap happen 50% of the time.

  • 0=?@1e4 Does a random number between 0 and 9999 inclusive equal 0? Returns 1 one in 10000 times.
  • 120&A. Transposes the requires letters.
  • Conditional execution at rate according to step 1 happens as a result of the way & works when invoked dyadically.

alternative 1, 27 bytes

4|.'raftMin','ec'|.~0=?@1e4

Try it online!

Rotate |. the string 'ec' with probability 1/10k, then append it to the string 'raftMin, then rotate the result by 4.

alternative 2, 28 bytes

'Minecraft'C.~3<@,4#~0=?@1e4

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 25 bytes for 120&A. one. \$\endgroup\$ – Bubbler Apr 25 at 23:35
5
\$\begingroup\$

Python 2, 62 61 bytes

-1 byte thanks to xnor!

from random import*
print'Min%sraft'%'ceec'[random()>1e-4::2]

Try it online!

If a probability of \$\left({92 \over 256}\right)^9 \approx 0.0000999841\$ to print Minceraft is fine, 59 bytes is possible:

import os
print'Min%sraft'%'ceec'[max(os.urandom(9))>91::2]

Try it online!


Python 2, 63 bytes

from random import*
print'Min%xraft'%(236-30*0**randrange(1e4))

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The CE/EC reversal is cute but it turns out shorter to just do a generic [::2] selector: TIO \$\endgroup\$ – xnor Apr 26 at 5:01
5
\$\begingroup\$

Python 3 - 45 42 41 Bytes

41 bytes with the constraint of running from a different process every run.

print(f"Min{'ceec'[id(0)%4e4>1::2]}raft")

42 bytes with limited randomness unless running a different process each time [*].

print(f"Min{'ceec'[id({})%4e4>1::2]}raft")

The idea was to use the same wrapper as in here, but a different RNG:
Create a new object (a set dict in this case, because it takes 5 2 characters set() {}), and take the id() of that, which is its memory address.

The memory address acts like a uniform hash[*], which has 1/10000 1/40000 (thanks @ovs) chance to end with zeros.

Try it online!

Update to 42 bytes:
Instead of set(), use {} which is the dict constructor. Can't go shorter for dynamic object creation.

Try it online!

Update to 41 bytes: - use static object creation!
Thanks to @dingledooper
Works only if the program is run in a different process every run!
Instead of {}, use 0.
0 is an object in Python, so it has an address in virtual memory, and that address is constant for that object during the lifetime of the program. If we were to run that in a for loop, it would not be random.
However, if we run it in a new process every run, we get the desired randomness. This is the case in a stateless server.

Try it online!

[*] - Objects in Python are freed immediately when they are no longer referenced (reference counting). Thus, running the solution in a loop might always output the same id, as the memory is freed and allocated at the same address. This is OS dependent, and environment dependent, thus may not work as expected, or in a reproducible way.
Running a new process each time solves this issue.

\$\endgroup\$
11
  • \$\begingroup\$ Welcome to CGCC, that's a very nice answer! By my experimentation it seems that memory addresses of set() are always divisible by 4, which means you would need to change 1e4 to 4e4 to get the right probability. \$\endgroup\$ – ovs May 4 at 21:51
  • \$\begingroup\$ @ovs wow that's a very nice catch, thanks! \$\endgroup\$ – Gulzar May 4 at 21:55
  • 2
    \$\begingroup\$ Wow. And I thought using time was nice... \$\endgroup\$ – EnderShadow8 May 4 at 23:09
  • \$\begingroup\$ Does id(0) work here? \$\endgroup\$ – dingledooper May 5 at 9:06
  • 1
    \$\begingroup\$ @Jakque I think this has to be OS specific. I would like to ask a question about this in SO, please add the specifications on which you tested, and the code. \$\endgroup\$ – Gulzar May 10 at 7:03
4
\$\begingroup\$

Swift, 55 53 bytes

print(.random(in:1...1e4)<2 ?"Minceraft":"Minecraft")

Try it online!

This is also my first Code Golf post.

Thanks to @Dingus for getting taking off 2 bytes!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Welcome to CGCC! 53 bytes with two small tweaks. \$\endgroup\$ – Dingus Apr 26 at 2:08
  • \$\begingroup\$ @Dingus Had no idea you could do 1e4, thanks! Also the < is smart to remove the ==. \$\endgroup\$ – George_E Apr 26 at 12:04
3
\$\begingroup\$

JavaScript, 51 44 bytes

_=>`Min${Math.random()*1e4>1?'ec':'ce'}raft`

try it online

That's a lotta bytes for such a simple task...

-7 thanks to the OP

\$\endgroup\$
10
  • 1
    \$\begingroup\$ 44 bytes: _=>`Min${Math.random()*1e5>1?'ec':'ce'}raft` - Try it online! \$\endgroup\$ – A username Apr 25 at 10:48
  • \$\begingroup\$ or a=>`Min${+new Date%10001?'ec':'ce'}raft`; but doesn't work consecutively \$\endgroup\$ – Alex bries Apr 25 at 10:59
  • \$\begingroup\$ What's strange here is that someone still upvoted my answer even though I (accidentally) used 1e5 instead of the correct 1e4. \$\endgroup\$ – ophact Apr 25 at 11:15
  • 5
    \$\begingroup\$ Why not >1e-4 if you use Math.random()? \$\endgroup\$ – l4m2 Apr 25 at 12:48
  • 1
    \$\begingroup\$ @TimSeguine your right, then it should be 37 bytes _=>"Min${new Date%1e4?'ec':'ce'}raft" \$\endgroup\$ – Alex bries Apr 27 at 12:47
3
\$\begingroup\$

Factor, 40 38 bytes

1e-4 [ "Minceraft"] [ "Minecraft"] ifp

Try it online!

-2 bytes thanks to @Bubbler!

Factor has a version of if called ifp that calls either quotation depending on a probability.

There is also an interpolating version that is slightly longer:

1e4 random 1 < "ce""ec"? [I Min${}raftI]
\$\endgroup\$
2
  • \$\begingroup\$ You can omit spaces after closing " :) \$\endgroup\$ – Bubbler Apr 26 at 0:01
  • \$\begingroup\$ @Bubbler Thanks. \$\endgroup\$ – chunes Apr 26 at 0:14
3
\$\begingroup\$

05AB1E, 19 18 bytes

„ecтnиćRªΩ”–·ÿraft

Try it online!

Run 10000 times

„ec      push string "ec"
т        push 100
n        squared, 10000
и        repeat, push ["ec"]*10000
ć        head extract
R        reverse
ª        append
Ω        choose random element
”–·ÿraft push "Min" + tos + "raft", which is implicitly outputed
\$\endgroup\$
0
3
\$\begingroup\$

Mathematica, 48 44 43 41 bytes

If[Random[]<.1^4,"Minceraft","Minecraft"]

Here's a simple unit test which found a bug in my first version.

Table[If[Random[]<.1^4,"Minceraft","Minecraft"], {ix, 10^6}] // Counts

And the result:

<|"Minecraft" -> 999909, "Minceraft" -> 91|>
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Nice work. To save 4 bytes, note that Random[] does the same thing as RandomReal[]; it's been deprecated since v6 but it still works. \$\endgroup\$ – Michael Seifert Apr 27 at 13:54
  • 1
    \$\begingroup\$ 41 bytes without the <>s. \$\endgroup\$ – att Apr 27 at 23:06
  • \$\begingroup\$ @att, I thought I had tested that idea. Obviously not. It's very pleasing to me, that this version is shorter, and more readable. \$\endgroup\$ – John Apr 28 at 12:40
3
\$\begingroup\$

JavaScript, 37 bytes

_=>`Min${new Date%1e4?'ec':'ce'}raft`

Try It Online

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf, and nice first answer! \$\endgroup\$ – Makonede May 5 at 22:17
  • 1
    \$\begingroup\$ Thanks, wonder if anything can be improved here! \$\endgroup\$ – mmaismma May 6 at 6:22
  • \$\begingroup\$ I'm not that fluent with JavaScript, so I can't really see any improvements you could make. But there might be a way! \$\endgroup\$ – Makonede May 6 at 16:16
2
\$\begingroup\$

05AB1E, 25 24 23 21 bytes

’£Ì³±’™D„ecÂ:‚тnLΩΘè™

Try it online!

I am once again grateful for Kevin's string compressor for providing me with the compressed strings.

Explained (old)

.•2žéhαP”·úεÕŸ•#тnLΩ1Qè™
.•2žéhαP”·úεÕŸ•#         # the list ["minecraft", "minceraft"]
                тnLΩ1Qè  # indexed at the position (random.randint(1, 100 ** 2) == 1)
                       ™ # title cased
\$\endgroup\$
3
2
\$\begingroup\$

Jelly (fork), 16 bytes

ȷ4XỊị“ẹ?ŀɼƲṬ`Ỵȧ«

Try it online!, or rather, don't

Tested on commit 6167f95, made on March 13th. Doesn't work on the latest commit due to a bug (a.k.a I accidentally removed the functionality that makes this work)

How it works

ȷ4XỊị“ẹ?ŀɼƲṬ`Ỵȧ« - Main link. Takes no argument
ȷ4               - 10000
  X              - Random integer between 1 and 10000
   Ị             - Turn 1 into 1 and everything else into 0
     “ẹ?ŀɼƲṬ`Ỵȧ« - Compressed dictionary string "Minceraft Minecraft", split on spaces
    ị            - Index into the list of words

“...« is a new string terminator introduced in my fork that's equivalent to “...»Ḳ¤/“...»Ỵ¤ in the current version of Jelly. It decompresses the string in between the “...«, then splits on whitespace.

\$\endgroup\$
2
\$\begingroup\$

Bash, 59 bytes

printf "%0.sMinecraft\n" {0..9999}|sed '1s/ec/ce/'|shuf -n1

Try it online!

Change 9999 to 1 to see it work with 50% probability.

Repeats the line "Minecraft" 10,000 times. Changes the first line only to "Minceraft". Shuffles the lines randomly and returns the first.

\$\endgroup\$
1
  • \$\begingroup\$ -1 byte: Replace \n to actual newline character. Try It Online \$\endgroup\$ – mmaismma May 5 at 8:39
2
\$\begingroup\$

Ruby, 35 34 bytes

$><<"Min#{rand<1e-4?:ce: :ec}raft"

Try it online!

Thanks to Dingus for a saved byte.

\$\endgroup\$
0
2
\$\begingroup\$

PHP, 40 32 29 bytes

<?=Min,rand()%1e4?ec:ce,raft;

Try it online!

Not a bad score for good ol' PHP

Or even shorter if we allow plain text ouside of the PHP tags (Thanks to Tim Seguine)

PHP, 33 29 28 bytes

Min<?=rand()%1e4?ec:ce?>raft

Try it online!

EDIT: saved another number of bytes by removing all quotes, inspired by another suggestion from Tim Seguine

EDIT 2: thanks again to Tim Seguine, now using rand()%1e4 instead of rand(0,1e4) which is not even shorter but more accurate, (at least in TIO, so far as getrandmax() has a high value), and using , to remove the round brackets

\$\endgroup\$
13
  • 1
    \$\begingroup\$ isn't this 1 in 10001 instead of 1 in 10000 ? \$\endgroup\$ – MarcMush Apr 26 at 13:12
  • \$\begingroup\$ @MarcMush yes, totally, like many other answers, including the currently most upvoted one. It's as the question states, "on average".. \$\endgroup\$ – Kaddath Apr 26 at 13:58
  • \$\begingroup\$ To have an "exact random chance" to happen, we could just have 9999 instead of 1e4 for 1 byte more \$\endgroup\$ – Kaddath Apr 26 at 14:07
  • \$\begingroup\$ If you move the tags around you can save 7 bytes: Min<?=rand(0,1e4)?'ec':'ce'?>raft \$\endgroup\$ – Tim Seguine Apr 27 at 9:59
  • 1
    \$\begingroup\$ I'll stop posting after this I swear: you can also remove the parens and dots by exploiting comma operators behavior wrt echo which coincidentally fixes the operator precedence issues that PHP's ternary operator has for this golf: <?=Min,rand()%1e4?ec:ce,raft; At this point it almost doesn't even look like real code anymore \$\endgroup\$ – Tim Seguine Apr 27 at 12:19
2
\$\begingroup\$

Wolfram Language, 50 47 42 bytes

Thanks to MarkMush for -1 byte and Michael Seifert for -4 bytes

If[Random[]<.1^4,"Minceraft","Minecraft"]&

Try it online!

Unfortunately, joining strings doesn't help to shorten this at all; the following is one byte longer:

"Min"<>If[Random[]<.1^4,"ce","ec"]<>"raft"&

Previous solution:

RandomChoice[{9999,1}->{"Minecraft","Minceraft"}]&

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ If you're OK with deprecated functions, Random[] does the same thing as RandomReal[] and saves you four bytes. \$\endgroup\$ – Michael Seifert Apr 27 at 13:57
2
\$\begingroup\$

Julia, 39 bytes

f()="Min$(rand()<1e-4 ? :ce : :ec)raft"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C# (Visual C# Interactive Compiler), 54 53 bytes

-1 thanks to caird coinheringaahing

_=>$"Min{(new Random().Next(10000)<1?"ce":"ec")}raft"

Try it online!

\$\endgroup\$
2
2
\$\begingroup\$

JavaScript (V8), 56 50 48 bytes

print(`Min${1e4*Math.random()<2?"ce":"ec"}raft`)

Try it online!

Credit to @caird for removing 2 bytes! (Took off a semicolon and changed ==5 to <2)

\$\endgroup\$
4
1
+100
\$\begingroup\$

Vyxal, R, 21 bytes, Courtesy of Lyxal and ManishKundu

«ɽL3Gp↵¢¨Π°ꜝ«½k2℅1=iǐ

Try it Online!

Vyxal, 30 bytes

`Min`k2ʀ℅1>[`ec`|`ce`]+`raft`+

Try it Online!

Well someone help me to compress these strings.... no no don't compress, compressing this yield larger strings....

\$\endgroup\$
8
  • \$\begingroup\$ I think you can just push the strings to the stack and use the s flag to concatenate them, so you can remove the +s \$\endgroup\$ – caird coinheringaahing Apr 25 at 11:46
  • \$\begingroup\$ @cairdcoinheringaahing i have tried that way earlier but it didn't work \$\endgroup\$ – Wasif Apr 25 at 11:50
  • 1
    \$\begingroup\$ I think that might be a bug then. If you remove the +s and just add a W though, you can get 29 bytes \$\endgroup\$ – Manish Kundu Apr 25 at 12:09
  • 2
    \$\begingroup\$ how about 22 bytes? \$\endgroup\$ – lyxal Apr 25 at 12:11
  • 1
    \$\begingroup\$ or this for 21 bytes? \$\endgroup\$ – lyxal Apr 25 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.