Create a Magic 8 Ball

34

6

As a child, my friend had a magic 8 ball that we would ask questions to and see what the fate of that question was.

Challenge

Your challenge is to write a program (or function) that when run (or called), outputs (or returns) a random answer from the possible answers below. (Random being: each output should have a nonzero chance of occurring but they do not need to meet any other criteria)

The possible answers from the Magic 8-ball are (case-insensitive):

It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yep
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

Input

No input.

Output

A random choice from above. Case does not matter.

Rules

Standard loopholes are not allowed.

This is , so the shortest code in bytes for each language wins!

DevelopingDeveloper

Posted 2018-03-07T21:04:01.050

Reputation: 1 415

Is using a library / external files with all the words acceptable?? – Dat – 2018-03-07T21:20:25.757

2I changed "no input allowed" to "no input", some languages require blank/null arguments as inputs. – Rɪᴋᴇʀ – 2018-03-07T21:21:37.500

@Dat I am going to have to say no. This challenge is to find a clever way to output those values, not to save a bunch of bytes by printing different lines of an external file. – DevelopingDeveloper – 2018-03-07T21:24:17.053

12Is it me or someone is downvoting every answers?????? – Dat – 2018-03-07T21:33:11.270

1

@Dat I posted something here in meta to discuss this. I have upvoted every answer, as I always do for answers that fulfil the requirements on my questions. Maybe a moderator will intervene...

– DevelopingDeveloper – 2018-03-07T21:42:06.163

37@Dat Signs point to yes – mbomb007 – 2018-03-07T22:10:58.367

1@mbomb007 My favorite comment I have seen on PPCG thus far! – DevelopingDeveloper – 2018-03-07T22:20:49.373

Answers

22

SOGL V0.12, 166 bytes

,▓a⁰²z○½℮ķčλ─fj[Ycψ-⁸jΔkÆΞu±⁄│(┼∞׀±q- υ~‼U/[DΓ▓νg⁸⅝╝┘¤δα~0-⁄⅝v⁄N⁷⁽╤oο[]āŗ=§№αU5$┌wΨgΘ°σΖ$d¦ƨ4Z∞▒²÷βΗ◄⁴Γ■!≤,A╬╤╬χpLΧ⁸⁽aIΘād⁵█↔‚\¶σΞlh³Ζ╤2rJ╚↓○sēχΘRψΙ±ιΗ@:┌Γ1⁷‘Ƨ! ΘlΨιw

Try it Here!

\o/ every word was in SOGLs dictionary!

dzaima

Posted 2018-03-07T21:04:01.050

Reputation: 19 048

This is an awesome answer!!! – DevelopingDeveloper – 2018-03-07T22:24:44.830

I'd love to take a look at SOGL's compression engine, but unfortunately, I don't speak JavaScript :( – caird coinheringaahing – 2018-03-07T22:46:52.400

Wait, SOGL is a JavaScript-based language? – Shaggy – 2018-03-07T23:52:36.393

@cairdcoinheringaahing SOGL is written in Processing, and the relevant compression files are here and here. Though Processing is a Java-based language :p

– dzaima – 2018-03-08T05:49:56.670

18

><>, 438 bytes

x|o<"Yep"
x|^"Most likely"
x|^"Signs point to yes"
x|^"As I see it, yes"
x|^"Without a doubt"
x|^"Ask again later"
x|^"Don't count on it"
x|^"Cannot predict now"
x|^"Very doubtful"
x|^"My reply is no"
x|^"My sources say no"
x|^"Outlook not so good"
x|^"Reply hazy try again"
x|^"Better not tell you now"
x|^"Concentrate and ask again"
x|^"It's certain"
x|^"Outlook good"
x|^"Yes definitely"
x|^"You may rely on it"
x|^"It is decidedly so"

Try it online!

Not that interesting, but I think it's the first answer where the randomness is not uniform. I put all the negative messages as least likely :)

Some explanation:

The pointer starts going right at the first line. x changes the pointer to a random cardinal direction. If it goes up or down, it just encounters a different x. If it goes right, it bounces off the | and hits the same x. If it goes left, it wraps around and pushes that line's text to the stack. Most lines then hit the same track of ^ which changes the direction to upwards. This loops over the o on the first line, which outputs the stack until empty. The special case is the Yep line, which has the horizontal loop |o< instead.

Jo King

Posted 2018-03-07T21:04:01.050

Reputation: 38 234

7I will use this one. It (almost) always gives a positive response. Unfortunately the answer also smells fishy... – Suppen – 2018-03-08T15:07:13.863

15

Python 2, 369 368 bytes

print"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.')[id(0)/7%20]

Python 3, 371 bytes

print("It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.')[hash(id)%20])

I was previously using the hash builtin to index (hash(id)%20), which returns a random value per-start of the Python interpreter ever since https://bugs.python.org/issue13703. It's not random for the empty-string though (always 0), so need to use something else, the id builtin!

On second look, I could use id directly, but it seems to always produce even numbers. IIRC, id(object) in CPython just returns the memory location of object, so this makes sense. Maybe if I used Jython or IronPython, I could skip the divide-by-7. Anyways, hash(id) vs id(0)//7 is equal in Python 3, but can use the / operator for truncating integer division in Python 2, saving a byte.

Nick T

Posted 2018-03-07T21:04:01.050

Reputation: 3 197

13

PowerShell, 354 bytes

"It is certain0It is decidedly so0Without a doubt0Yes definitely0You may rely on it0As I see it, yes0Most likely0Outlook good0Yep0Signs point to yes0Reply hazy try again0Ask again later0Better not tell you now0Cannot predict now0Concentrate and ask again0Don't count on it0My reply is no0My sources say no0Outlook not so good0Very doubtful"-split0|Random

Try it online!

Ho-hum. Takes all the outcomes, concatenated together with 0s, then -splits on 0 to create an array of strings. Passes that array to Get-Random which will randomly select one of them. That's left on the pipeline and output is implicit.

AdmBorkBork

Posted 2018-03-07T21:04:01.050

Reputation: 41 581

11

Python 2, 385 bytes

-1 byte thanks to ovs.

from random import*
print choice("It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.'))

Try it online!

totallyhuman

Posted 2018-03-07T21:04:01.050

Reputation: 15 378

22@Downvoter, may I ask why you've downvoted every answer? – totallyhuman – 2018-03-07T21:30:14.397

7That strikes me as suspicious voting behaviour, I'd suggest flagging the question for a mod's attention so they can investigate. – Shaggy – 2018-03-07T23:54:03.477

9

Applescript, 391

I love how AppleScript's lists have a some item method:

{"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it,yes","Most likely","Outlook good","Yep","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful"}'s some item

Digital Trauma

Posted 2018-03-07T21:04:01.050

Reputation: 64 644

5Cue the mean-spirited downvoter-of-all-answers in 3, 2, 1... Go on - I dare you to reveal who you are and explain your downvote rationale. Or will you continue to anonymously lurk in the shadows? – Digital Trauma – 2018-03-08T00:56:53.330

7

Bash + GNU utilities, 230

  • 15 bytes saved thanks to @Dennis.
sed 1d $0|zcat|shuf -n1
# zopflied 8 ball list

The binary zopfli output is not well represented here; instead you can reconstruct the script from base64 encoded data:

base64 -d << EOF > 8ball.sh
c2VkIDFkICQwfHpjYXR8c2h1ZiAtbjEKH4sIAAAAAAACAz1QSZJCMQjd5xRv1fOlMEGlzIdfgbRF
n75NOayYeYMExFF5BImWe9W4SuPWE27lKnG2GSA0m4coyWvhKCrBPUvaxEaJcStgColCDoEzQ+IH
t/WymQe6XNa+zehmF5zMWknei8tJHbuJBsKw9gfvPXGmv0SMBJ0WNfLLPUOn4FEOHMEDaoHg3rGI
qF1LJV29fXCTGveWaWWNQcEgbXi9Ks30PVBtauBOfkvc4cWhtkq3OSo7nBJqLwELxO2u45dH3u05
zv4=
EOF

Note, as allowed by the question, the compressed data decompresses to all lower case. This makes zopfli compression a bit more efficient and saves 16 bytes.

Digital Trauma

Posted 2018-03-07T21:04:01.050

Reputation: 64 644

tail +2 doesn't work for me, but sed 1d $0 saves a byte anyway. Also, since output to STDERR is allowed by default, I don't think you need the exit. Also, the last ten bytes of the program can be removed. – Dennis – 2018-03-08T00:15:52.167

@Dennis thanks! Extra output to STDERR always makes me feel a little uncomfortable, but I guess I should run with it. – Digital Trauma – 2018-03-08T00:40:35.697

6

Charcoal, 203 184 bytes

‽⪪”}∨74Dυ3↖u➙H�↖vI⁻VR‹ψ#�Ii»ψPNξ⮌≔;≡8ν}¬H⁺ºº↖H⁴K⌕êτ|⁼➙⟲W»″φ◨⟦(τ(jK“N\⍘“↷⊙ⅉvT>➙§⌊Fζ³⁻↔;TaÀ✳⁴≔67⍘i4¬⸿-A8⁻f7¡<⁰Zχ}ζ'¡¹→Oaε!OυP₂ïμ´MuP⁺M⮌1№-k¹№FvξDü⊟ζⅉ⁰xW:Dε7TvM₂⊞θC⪪Rε⁰“D¡⸿⁰″A⊕λξ↥~O·PE&”¶

Try it online! Link is to verbose version of code. Edit: Saved 19 bytes by lowercasing everything. Explanation:

  ”...”     Compressed string of newline-delimited responses
 ⪪     ¶    Split on newlines
‽           Random element
            Implicitly print

Neil

Posted 2018-03-07T21:04:01.050

Reputation: 95 035

6

R, 360 bytes

sample(readLines(),1)
It is certain
It is decidedly so
Without a doubt
Yes definitely
You may rely on it
As I see it, yes
Most likely
Outlook good
Yep
Signs point to yes
Reply hazy try again
Ask again later
Better not tell you now
Cannot predict now
Concentrate and ask again
Don't count on it
My reply is no
My sources say no
Outlook not so good
Very doubtful

Try it online!

Not exactly the most elegant solution. R has a neat feature where stdin will redirect to the source file, so you can put (small) datasets into source code, saving bytes for string splitting or worse, constructing the vector itself (all those quotes add up in a hurry). Along with builtins for random sampling, this makes a short-ish answer.

Giuseppe

Posted 2018-03-07T21:04:01.050

Reputation: 21 077

5

Retina, 333 331 321 bytes


0cert10decided2so¶with34a d3bt¶yes definitely¶y3 ma5re26as i see it, yes¶mos4likely7good¶yep¶signs poin4to yes¶rep2haz5tr5ag18ain later¶better 94tell y3 9w¶can94predic49w¶concentrate and 81don'4c3n46m5rep2is 9¶m5s3rces sa59794so good¶ver5d3btful
9
no
8
ask ag
7
¶3tlook 
6
on it¶
5
y 
4
t 
3
ou
2
ly 
1
ain¶
0
it is 
G?`

Try it online! Edit: Saved 1 byte by compressing doubt and 1 byte by lowercasing everything so I could compress reply. Then saved 10 bytes by using @Leo's Retina Kolmogorov golfer on the lowercased text (which coincidentally is the number of bytes it saved on my 333-byte answer).

Neil

Posted 2018-03-07T21:04:01.050

Reputation: 95 035

323 bytes by using my Retina 0.8 Kolmogorov golfer – Leo – 2018-03-07T22:46:53.990

@Leo Note that Retina 0.8.2 is a different language – mbomb007 – 2018-03-07T22:57:07.517

@mbomb007 I know, but for simple substitutions like these it has the same syntax as Retina 1.0. I was just pointing out that the Kolmogorov golfer was written for an older version of Retina but it is still usable in this case. – Leo – 2018-03-07T23:00:31.723

4

Coconut, 380 bytes

Coconut port of totallyhuman's answer

from random import*
choice$("It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split('.'))

Try it online!

ovs

Posted 2018-03-07T21:04:01.050

Reputation: 21 408

4

Jelly, 201 bytes

-2 bytes thanks to Mr. Xcoder. -1 byte thanks to user202729.

“æ⁽IẊ?⁽ʋṠ¶ÐƝKW¬ḃỴɓ⁾:Eṇ⁵ṾɱD×⁴2ṇỤðċỊ¥ḷƬị÷ṣÐṆⱮ$u²OŀṚƁȮ1⁼ṁ$bp⁾v]Ɠ-/NẓḲnỵdḳḋ½ȥṿ=kv¥ɓl[kR AḞ¶gḣḞiẊŒẊḳçȤ⁻Ɱʋx:ØṖ|zY=ṾḌẓY1Ḃ$50d⁹⁸ŀhʂƤṢM;ḢoƁṾ⁷-uṙu¡Ọ3ṣȮ@⁹ðẹȥXƭ⁸|ƬẋẆḢɠœxḳsĿƘ(0çỌ~A½YIEFU3Ọ=⁷ɗḷBḷİṄhṗgṡƊẏẏḄ#Ṙʋ$ʂȷĠ»ỴX

Try it online!

Damn, SOGL's compression is good.

totallyhuman

Posted 2018-03-07T21:04:01.050

Reputation: 15 378

202 bytes – Mr. Xcoder – 2018-03-07T22:00:18.660

201 bytes. Just append the 2 last characters. – user202729 – 2018-03-11T16:30:52.567

(I mean, append ỴX to the end of the code so it chooses randomly from one of them) – user202729 – 2018-03-11T16:36:52.927

4

Ruby, 362 361 bytes

puts"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split(?.).sample

Try it online!

  • 1 byte thanks to @benj2240

BigRon

Posted 2018-03-07T21:04:01.050

Reputation: 149

You can shave off a byte with ?. instead of '.'. – benj2240 – 2018-03-08T21:54:09.817

@benj2240 wow, I hadn't seen that before. Very cool. – BigRon – 2018-03-19T21:00:01.060

1

I had to go digging for the documentation on that ? single character string literal

– BigRon – 2018-03-19T21:12:57.220

4

05AB1E, 171 bytes

“€•€ˆ‹ì€•€ˆŸíly€Ê„›€…¬³…ܴ΀˜€‰€•€œ I€È€•,…Ü‚¢îÙ®½‚¿ yepŸé…®€„…Ü…ƒ hazy‡Ü†îˆ¹†îŠ´…瀖ˆœ€î€Ó€©notßä€Óä考ˆ¹†î€·n'tš‹€‰€•€¯…ƒ€ˆ€¸€¯Žç…耸®½€–€Ê‚¿‚Ò¬³ful“#•8∞f{ʒβ®•6в£ðýΩ

Try it online!

Explanation

“ ... “ pushes a string of all the required words.
Some words are taken directly from the 05ab1e dictionary.
Some are written out in plain ascii (like haze).
Some are combined dictionary and ascii (like do+n't).

Then the processing code is:

#                 # split string on spaces to a list of words
 •8∞f{ʒβ®•        # push the number 2293515117138698
          6в      # convert to a list of base-6 numbers 
                  # ([3,4,3,2,5,5,2,2,1,4,4,3,5,3,4,4,4,4,4,2])
            £     # group the list into sublists of these sizes
             ðý   # join on spaces
               Ω  # pick one at random

Emigna

Posted 2018-03-07T21:04:01.050

Reputation: 50 798

Try it online! - 176 with bruteforce conversion. – Magic Octopus Urn – 2018-03-13T16:24:04.380

1@MagicOctopusUrn: I think it's 182 with , and ' added. – Emigna – 2018-03-13T17:40:52.523

D'oh! Ah I see it, yes. By the way remove the input from your TIO, it's confusing a little. – Magic Octopus Urn – 2018-03-13T18:32:09.710

@MagicOctopusUrn: Doh! Thanks. I wasn't aware I'd left that in there :P – Emigna – 2018-03-13T20:15:16.453

166: TIO. Thrice -1 from using new dictionary words ( ye, don, and ha), and -2 from sorting the list by word count and using delta compression.

– Grimmy – 2019-09-11T13:00:17.470

163 (TIO) by using run-length encoding instead of deltas (requires switching to modern 05AB1E).

– Grimmy – 2019-09-11T13:05:12.137

4

T-SQL, 393 bytes

SELECT TOP 1*FROM STRING_SPLIT('It is certain-It is decidedly so-Without a doubt-Yes definitely-You may rely on it-As I see it, yes-Most likely-Outlook good-Yep-Signs point to yes-Reply hazy try again-Ask again later-Better not tell you now-Cannot predict now-Concentrate and ask again-Don''t count on it-My reply is no-My sources say no-Outlook not so good-Very doubtful','-')ORDER BY NEWID()

The function STRING_SPLIT is only available in SQL 2016 and later.

Best I could get for prior versions using VALUES('It is certain'),('It is decidedly so'),... was 464 characters.

Formatted, just so you can see the working part:

SELECT TOP 1 *
FROM STRING_SPLIT('It is certain-It is decidedly so-...', '-')
ORDER BY NEWID()

NEWID() generates a new, pseudo-random GUID, so is a way to do a pseudo-random sort.

BradC

Posted 2018-03-07T21:04:01.050

Reputation: 6 099

3

Python 3, 386 bytes

from random import*
lambda:choice("It is certain;It is decidedly so;Without a doubt;Yes definitely;You may rely on it;As I see it, yes;Most likely;Outlook good;Yep;Signs point to yes;Reply hazy try again;Ask again later;Better not tell you now;Cannot predict now;Concentrate and ask again;Don't count on it;My reply is no;My sources say no;Outlook not so good;Very doubtful".split(';'))

Dat

Posted 2018-03-07T21:04:01.050

Reputation: 879

3

Java 8 , 433, 392, 380, 379 bytes

 a->"It is certain~It is decidedly so~Without a doubt~Yes definitely~You may rely on it~As I see it, yes~Most likely~Outlook good~Yep~Signs point to yes~Reply hazy try again~Ask again later~Better not tell you now~Cannot predict now~Concentrate and ask again~Don't count on it~My reply is no~My sources say no~Outlook not so good~Very doubtful".split("~")[(int)(Math.random()*20)]

Try it online!

  • 41 bytes thanks to AdmBorkBork!
  • 10 bytes thanks to Kevin!
  • 1 byte thanks to Oliver!

DevelopingDeveloper

Posted 2018-03-07T21:04:01.050

Reputation: 1 415

2

Surely you can use String.split() to save a bunch of bytes — https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split%28java.lang.String%29

– AdmBorkBork – 2018-03-07T22:47:47.883

2

As @AdmBorkBork stated, you can save 41 bytes using String#split. Also, you can save an additional 11 bytes using (int)(Math.random()*20) instead of new java.util.Random().nextInt(20). And the semi-colon isn't counted towards the byte-count for lambdas. So in total: 380 bytes.

– Kevin Cruijssen – 2018-03-08T09:31:10.603

2There's an extra space in your answer and in @KevinCruijssen's golf: use Don't instead of Don' t. – Olivier Grégoire – 2018-03-11T20:24:49.770

3

Javascript, 372 bytes

-10 bytes thanks to Shaggy

_=>"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful".split`.`[Math.random()*20|0]

Try it online!

SuperStormer

Posted 2018-03-07T21:04:01.050

Reputation: 927

1Use bitwise OR instead of Math.floor() to save 7 bytes: Math.random()*20|0. – Shaggy – 2018-03-08T11:04:02.340

3

05AB1E, 208 217 bytes

"don'".•W˜FζÃT¥„ò.1₁∍Y<`Ì°5jýúž+ìmHSéÁ¬–xȃø‚ž}_Øviòª§l["]0â^)„2æδ∍G1∊EÌLÝ'îôΛβ;ƒĀαÏw L°gðÈγ³€wE‘f饤šαrˆQŠë¢-º8Æ~ÁŠ∍δBx®(β™Žü6»ƶÙÐ~†«\%ÍŒΘ-´sÈƵJŸ₃H7Ó˜:Å∍₂èÑï∞—Râú'óвb…ÓUXʒǝ₄ÝrÒ₄¨÷ä褓oθWÎλî~bj(Ri
Þиe‘ãj]•", yes"J'x¡Ω

Try it online!

Pretty basic solution. The possible answers are concatenated with the character x (since it's not present in the answers) and then compressed (inside the ), 'x¡Ω split on x and pop a random choice.

Thanks to @Emigna for pointing out that the alphabet compression doesn't like ' or , much. Fixed by surrouding the compressed string with don' and , yes.

Kaldo

Posted 2018-03-07T21:04:01.050

Reputation: 1 135

Nice idea to split on a character not present. Unfortunately alphabet compression replaces , and ' with spaces, so the output for those 2 lines are wrong. – Emigna – 2018-03-08T10:34:17.047

@Emigna Thanks a lot for pointing it out ! I'm wondering if a better fix doen't exist for this issue... I could have used other non-used characters in the answers but there are only two: q and x :-( – Kaldo – 2018-03-08T10:52:22.850

3

Perl, 366

print((split",","It is certain,It is decidedly so,Without a doubt,Yes definitely,You may rely on it,As I see it,yes,Most likely,Outlook good,Yep,Signs point to yes,Reply hazy try again,Ask again later,Better not tell you now,Cannot predict now,Concentrate and ask again,Don't count on it,My reply is no,My sources say no,Outlook not so good,Very doubtful")[rand 19])

Flying_whale

Posted 2018-03-07T21:04:01.050

Reputation: 139

2I found a bug. You can't use comma as a separator because 1 of the possible answers from the Magic 8-ball contains a comma: As I see it, yes. – g4v3 – 2018-03-09T16:56:46.033

1I'd suggest that you use a single digit as the separator. It would save 1 byte, as the quotes are no longer needed, but a space must still be added to separate the digit and split. – g4v3 – 2018-03-09T17:31:57.623

1Also, you can omit parenthesis for print and save 1 more byte. Just put a unary plus sign before the list: print((0..9)[5]) would become print+(0..9)[5]. – g4v3 – 2018-03-09T17:38:27.830

3

PHP, 412 385 337 384 bytes

<?php $a=explode(1,"It is certain1It is decidedly so1Without a doubt1Yes definitely1You may rely on it1As I see it, yes1Most likely1Outlook good1Yep1Signs point to yes1Reply hazy try again1Ask again later1Better not tell you now1Cannot predict now1Concentrate and ask again1Don't count on it1My reply is no1My sources say no1Outlook not so good1Very doubtful");echo$a[array_rand($a)];

Try it online!

Fairly straight forward solution. Split the string by a delimiter(in this case 1) and choose a random element from the array.

Andrew

Posted 2018-03-07T21:04:01.050

Reputation: 139

Welcome to PPCG! I've made some minor formatting changes to your post, and have a couple little suggestions - 1, you need to add a space after php to get your code to compile; 2, you can replace '|' with 1 and all | with 1 for -2 bytes; 3 should consider changing your link for Trying it Online to TIO.run as is preferred by the community. – Taylor Scott – 2018-03-08T12:26:47.563

And here is a working version based off my feedback. Try it online!

– Taylor Scott – 2018-03-08T12:28:44.517

@TaylorScott It seems to be working fine on my enovironment without the space after the <?php tag. I'm running PHP 7.2.3-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Mar 6 2018 11:18:25) ( NTS ). Not sure if in previous versions that matters or not. Either way, I've edited the question. – Andrew – 2018-03-08T12:32:44.107

Ahh, it may just be the version - The link you provided uses PHP version 7.0.3, and it does not run on TIO.run without the space – Taylor Scott – 2018-03-08T12:39:20.273

Indeed. It's an int now, not a string. Gotta love(and hate) type coercion in PHP. It won't complain. – Andrew – 2018-03-08T12:45:50.223

2You could use <?= and echo the explode directly using [rand(0, 19)] instead of first adding to to a variable <?= explode("1", "str1str1str")[rand(0, 19)] – Jeroen – 2018-03-09T14:26:44.730

Change the string to all lower case (so it compresses better), gzcompress/base64_encode and use that string with gzuncompress base64_decode - gets it down to 352: <?php $a=explode(1,gzuncompress(base64_decode("eJw9UEluwzAM/MrceulFT1IkxiEsk4ZINVBfX8pGeuKC4SxkBxsKdc8sia+pUuFKtU2Ypjf7S4cjo+p4eJq0AE8WdmozTR048kSPASpgT9nAMKLovxHwdKg5Gu8LH1RNdcemWoPrTMabGE5lcbhe+E5nkL3y74T3ibwta9n2u0PLTj09yKNANM6oNSwjou9Usqzd2aly8XulUki8xx2yVPxTpary5Sg6Qvw2f6woSz7+ILpG09FLhLZIGZtPgCVieuf4obB5vec52h9Jf3yq[")));echo$a[array_rand($a)]; – manassehkatz-Moving 2 Codidact – 2018-03-11T16:49:33.583

You can save 4 bytes with shuffle($a);echo$a; – ub3rst4r – 2018-03-12T02:59:49.373

3

Befunge

1221 870 bytes (perimeter of the entire field is 33x36 30*29 charachters) Thanks to Jo King for helping me to remove the trailing nulls and urging me to change the randomizer.

"<"99+9+1+v
v         <
 >>>>>>>>>>55++v
 0123456789
>??????????<
 0123456789
 >>>>>>>>>>    v
               >88++p       v
v"It is certain"           
v"It is decidedly so"
v"Without a doubt"
v"Yes definitely"
v"You may rely on it"
v"As I see it, yes"
v"Most likely"
v"Outlook good"
v"Yep"
v"Signs point to yes"
v"Reply hazy try again"
v"Ask again later"
v"Better not tell you now"
v"Cannot predict now"
v"Concentrate and ask again"
v"Don't count on it"
v"My reply is no"
v"My sources say no"
v"Outlook not so good"
v"Very doubtful"
>:#,_@

The top line puts the '<' character and the x-position (28) where it should go on the stack. Then we enter the sort of random number generator. This could be improved, but this is what I could deliver on short notice... The "random" number is offset to get the actual "random" line to read.

After the random number is generated, we put the '<' character at that line and push the letters on the stack and on the bottom line output them again.

Note; if you use the interpreter I linked to in this posts title you have to reclick the "Show" after each run, because the addition of the '<' character remains after execution.

rael_kid

Posted 2018-03-07T21:04:01.050

Reputation: 341

1

You're much better off using the same format as my ><> answer. Try it online!. As it is now, it also prints a bunch of null bytes at the end

– Jo King – 2018-03-08T21:40:09.403

Yeah, I know, I wanted the random number thingy not to be too biased, but I could've just used a single line of question marks. – rael_kid – 2018-03-09T06:53:32.287

You can at least golf a couple of hundred bytes of whitespace off, and change the last line to >:#,_@ to avoid printing null bytes. Oh, and add a TIO link. – Jo King – 2018-03-09T08:10:57.147

That's true, I'll post an update later today. – rael_kid – 2018-03-09T10:05:01.817

2

Red, 367 bytes

prin pick split{It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful}"."random 20

Try it online!

It doesn't seem really random in TIO (although it works just fine in the Red Console), that's why I added a random/seed to the header.

Galen Ivanov

Posted 2018-03-07T21:04:01.050

Reputation: 13 815

2

Excel, 399 Bytes

=CHOOSE(1+20*RAND(),"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yep","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful")

Since CHOOSE(X.Y,<>) is the same as CHOOSE(X,<>), no need for an INT

Not much golfing you can do here though...

Chronocidal

Posted 2018-03-07T21:04:01.050

Reputation: 571

2

Aceto, 345 + 1 = 346 bytes (+1 for -l flag)

"It is certain.It is decidedly so.Without a doubt.Yes definitely.You may rely on it.As I see it, yes.Most likely.Outlook good.Yep.Signs point to yes.Reply hazy try again.Ask again later.Better not tell you now.Cannot predict now.Concentrate and ask again.Don't count on it.My reply is no.My sources say no.Outlook not so good.Very doubtful"'.:Yp

Try it online!

Not overly interesting, but I can't think of anything shorter in this language, no compressed strings or anything.

"...."   push strings separated by periods
      '.  literal period
        :  split on period
         Y  shuffle stack
          p  print top

drham

Posted 2018-03-07T21:04:01.050

Reputation: 515

without the -l flag might look more interesting. – Laura Bostan – 2018-03-09T21:38:43.283

@LauraBostan But I don't know hilbert curves past type 3 – drham – 2018-03-09T21:39:08.783

and it's more bytes for all of the \n – drham – 2018-03-09T21:39:21.920

1But yes it would look more 'interesting' per se – drham – 2018-03-09T21:41:51.820

iup... the -l flag was added for golfing. However, I am not very fond of it, steals cheaply the whole point of the language. Maybe next version of Aceto will give up this flag. – Laura Bostan – 2018-03-09T21:46:24.110

Anyways, I am always happy to see new uses of Aceto :]. Welcome on Stack Exchange! – Laura Bostan – 2018-03-09T21:49:56.160

Thanks! I agree that yes, it is rather 'boring', but I liked aceto for it's relative golfiness, not its hilbert curve – drham – 2018-03-10T02:33:31.117

1

Excel-VBA, 362 341 339 Bytes

v=[1:1]:?v(1,Rnd*19)

Where A1:T1 contain the different options. Reads entire first row of sheet into array v and indexes a random point along the first 19 values.

Surprised to find that indexing an array doesn't require integer values

Greedo

Posted 2018-03-07T21:04:01.050

Reputation: 267

My concerns about your answer for Excel are even more so here, as the Worksheet is counted as a STDIN for Excel VBA, so this is closer to having pre-determined input – Taylor Scott – 2018-03-09T16:04:30.553

1

C - 426 bytes

char a[][99]={"It is certain","It is decidedly so","Without a doubt","Yes definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yep","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful"};int main(){int n;puts(a[n%20]);}

Uses an uninitialized variable mod 20 to index into an array of strings containing all possible outputs. Compilers complain that stdio.h isn't included, but it works OK. Probably because it just so happens to have the standard library linked in anyways. Lucky me.

Orion

Posted 2018-03-07T21:04:01.050

Reputation: 309

Worth noting on some implementations, an uninitialized variable has a value of 0, since the behavior is, well, undefined. Ask your magic 8-ball whether this is true on your machine. – Orion – 2018-03-09T08:40:24.163

1

Go, 530 Bytes

package main;import"fmt";func main(){for k:=range map[string]struct{}{"It is certain":{},"It is decidedly so":{},"Without a doubt":{},"Yes definitely":{},"You may rely on it":{},"As I see it, yes":{},"Most likely":{},"Outlook good":{},"Yep":{},"Signs point to yes":{},"Reply hazy try again":{},"Ask again later":{},"Better not tell you now":{},"Cannot predict now":{},"Concentrate and ask again":{},"Don't count on it":{},"My reply is no":{},"My sources say no":{},"Outlook not so good":{},"Very doubtful":{}}{fmt.Print(k);break}}

Please note that, on the Go Playground, because of how seeding works, it always gives the same result. When running on a regular computer, everything works as it should.
I think it is possible to save a bit more but my knowledge in Go stops there :)

Formatted and testable version

Nathanael C.

Posted 2018-03-07T21:04:01.050

Reputation: 19

Welcome to PPCG! The Go interpreter on Try It Online seems to use a random seed.

– Dennis – 2018-03-11T14:30:18.843

I must be terribly unlucky then D: – Nathanael C. – 2018-03-11T14:33:21.313

Are you refreshing the page? That would fetch the result from cache every time, so it won't change. Clicking the Run button will run the code again. – Dennis – 2018-03-11T14:35:34.193

I keep getting "It is certain" even after with a CTRL+R to hard refresh... I don't get it :x – Nathanael C. – 2018-03-11T15:08:27.063

Refreshing won't change the result; they are cached on the server side. Click the run button (play icon in a circle) or press Ctrl-Enter. – Dennis – 2018-03-11T15:29:51.403

Oh okay I'm completely stupid, that was me. Forget it .-. – Nathanael C. – 2018-03-11T18:44:41.427

Let us continue this discussion in chat.

– Nathanael C. – 2018-03-11T21:49:05.470

0

VBA, 358 bytes

An anonymous VBE immediate window function that takes no input and outputs to STDOUT.

?Split("It is certain1It is decidedly so1Without a doubt1Yes definitely1You may rely on it1As I see it, yes1Most likely1Outlook good1Yep1Signs point to yes1Reply hazy try again1Ask again later1Better not tell you now1Cannot predict now1Concentrate and ask again1Don't count on it1My reply is no1My sources say no1Outlook not so good1Very doubtful",1)(19*Rnd)

Taylor Scott

Posted 2018-03-07T21:04:01.050

Reputation: 6 709

-1

Excel Google Sheets, 319+21 = 342 340 Bytes

=INDEX(A:A,1+20*RAND(

Where cells A1:A19 contain the different output options. Reads from the array using a random index. Saves a whole load of bytes by avoiding a delimiter in the list

Saved 2 bytes thanks to Taylor Scott

Greedo

Posted 2018-03-07T21:04:01.050

Reputation: 267

I have some concerns about this answer - 1, with raw text and no delimiters, there are 319 bytes of data, and 2 I think that you should have to count have to count a single byte towards delimiting the cell data, because in its raw text represntation - that is if you were to store the data as a CSV (comma-delimited) or an ASC file - there would be a single , character separating the columns' values (or \n separating the rows) – Taylor Scott – 2018-03-09T16:01:19.903

That said, you can drop 2 bytes off of your score by switching to Google Sheets and dropping the terminal )) – Taylor Scott – 2018-03-09T16:02:35.103

-1

Java 8, 379 Bytes

b->"It is certain-It is decidedly so-Without a doubt-Yes definitely-You may rely on it-As I see it, yes-Most likely-Outlook good-Yep-Signs point to yes-Reply hazy try again-Ask again later-Better not tell you now-Cannot predict now-Concentrate and ask again-Don't count on it-My reply is no-My sources say no-Outlook not so good-Very doubtful".split("-")[(int)(Math.random()*20)]

Try it online

Twometer

Posted 2018-03-07T21:04:01.050

Reputation: 281

-1

C (gcc), 408 bytes

f(s){char*p="It is certain\0It is decidedly so\0Without a doubt\0Yes definitely\0You may rely on it\0As I see it, yes\0Most likely\0Outlook good\0Yep\0Signs point to yes\0Reply hazy try again\0Ask again later\0Better not tell you now\0Cannot predict now\0Concentrate and ask again\0Don't count on it\0My reply is no\0My sources say no\0Outlook not so good\0Very doubtful";for(s=time(0)%20;s;)*p++?0:s--;s=p;}

Try it online!

Users are hard to predict, making the timing of their decision to call the function pseudo-random enough for our purposes.

gastropner

Posted 2018-03-07T21:04:01.050

Reputation: 3 264