Crea una Magic 8 Ball


34

Da bambino, il mio amico aveva una palla magica 8 a cui faremmo domande e vedere quale fosse il destino di quella domanda.

Sfida

La tua sfida è scrivere un programma (o una funzione) che quando viene eseguito (o chiamato), genera (o restituisce) una risposta casuale dalle possibili risposte di seguito. (Random essere: each output should have a nonzero chance of occurring but they do not need to meet any other criteria)

Le possibili risposte dalla Magic 8-ball sono (senza distinzione tra maiuscole e minuscole):

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

Ingresso

Nessun input

Produzione

Una scelta casuale dall'alto. Il caso non ha importanza.

Regole

Non sono ammesse scappatoie standard .

Questo è , quindi vince il codice più breve in byte per ogni lingua!


2
Ho cambiato "nessun input consentito" in "nessun input", alcune lingue richiedono argomenti vuoti / nulli come input.
R

12
Sono io o qualcuno sta sottovalutando ogni risposta ??????
Dat

1
@Dat Ho pubblicato qualcosa qui in meta per discuterne. Ho votato a fondo ogni risposta, come faccio sempre per le risposte che soddisfano i requisiti delle mie domande. Forse interverrà un moderatore ...
DevelopingDeveloper

37
@DatSigns point to yes
mbomb007

1
@ mbomb007 Il mio commento preferito che ho visto su PPCG finora!
DevelopingDeveloper

Risposte:


22

SOGL V0.12 , 166 byte

,▓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

Provalo qui!

\ o / ogni parola era nel dizionario SOGLs!


Questa è una risposta fantastica !!!
DevelopingDeveloper

Mi piacerebbe dare un'occhiata al motore di compressione di SOGL, ma sfortunatamente non parlo JavaScript :(
caird coinheringaahing

Aspetta, SOGL è un linguaggio basato su JavaScript?
Shaggy

@cairdcoinheringaahing SOGL è scritto in Elaborazione e i relativi file di compressione sono qui e qui . Sebbene Processing sia un linguaggio basato su Java: p
dzaima

18

> <> , 438 byte

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"

Provalo online!

Non così interessante, ma penso che sia la prima risposta in cui la casualità non è uniforme. Ho messo tutti i messaggi negativi il meno probabile :)

Qualche spiegazione:

Il puntatore inizia a destra alla prima riga. xcambia il puntatore in una direzione cardinale casuale. Se va su o giù, incontra solo un diverso x. Se va bene, rimbalza |e colpisce lo stesso x. Se va a sinistra, si avvolge e inserisce il testo di quella riga nella pila. La maggior parte delle linee quindi colpisce la stessa traccia di ^cui cambia la direzione verso l'alto. Questo passa sopra la oprima riga, che genera lo stack fino a vuoto. Il caso speciale è la Yeplinea, che ha |o<invece il ciclo orizzontale .


7
Userò questo. Dà (quasi) sempre una risposta positiva. Purtroppo la risposta ha anche un odore di pesce ...
Suppen

15

Python 2, 369 368 byte

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 byte

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])

In precedenza utilizzavo hashbuiltin to index ( hash(id)%20), che restituisce un valore casuale per inizio dell'interprete Python da allora https://bugs.python.org/issue13703 . Tuttavia, non è casuale per la stringa vuota (sempre 0), quindi è necessario utilizzare qualcos'altro, l' idintegrato!

Al secondo sguardo, potrei usarlo iddirettamente, ma sembra produrre sempre numeri pari. IIRC, id(object)in CPython restituisce solo la posizione di memoria di object, quindi questo ha senso. Forse se avessi usato Jython o IronPython, avrei potuto saltare la divisione per 7. Comunque, hash(id)vs id(0)//7è uguale in Python 3, ma può usare l' /operatore per troncare la divisione dei numeri interi in Python 2, salvando un byte.


13

PowerShell , 354 byte

"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

Provalo online!

Ho-hum. Prende tutti i risultati, concatenati insieme a 0s, quindi-split s su 0per creare un array di stringhe. Passa l'array a Get-Randomcui selezionerà casualmente uno di essi. Rimane in cantiere e l'output è implicito.


11

Python 2 , 385 byte

-1 byte grazie a 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('.'))

Provalo online!


22
@Downvoter, posso chiederti perché hai annullato il voto per ogni risposta?
totalmente umano il

7
Questo mi sembra un comportamento di voto sospetto, suggerirei di segnalare la domanda all'attenzione di un mod in modo che possano indagare.
Shaggy

9

Applescript, 391

Adoro il modo in cui le liste di AppleScript hanno un some itemmetodo:

{"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

5
Indica il downvoter mediocre di tutte le risposte in 3, 2, 1 ... Vai avanti - ti sfido a rivelare chi sei e spiegare la tua logica negativa. O continuerai a nasconderti anonimamente nell'ombra?
Trauma digitale

7

Utilità Bash + GNU, 230

  • 15 byte salvati grazie a @Dennis.
sed 1d $0|zcat|shuf -n1
# zopflied 8 ball list

L'output binario di zopfli non è ben rappresentato qui; invece puoi ricostruire lo script dai dati codificati base64:

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

Nota, come consentito dalla domanda, i dati compressi vengono decompressi in tutte le lettere minuscole. Ciò rende la compressione zopfli un po 'più efficiente e consente di risparmiare 16 byte.


tail +2non funziona per me, ma sed 1d $0salva comunque un byte. Inoltre, poiché l'output su STDERR è consentito per impostazione predefinita, non penso che sia necessario exit. Inoltre, è possibile rimuovere gli ultimi dieci byte del programma.
Dennis

@Dennis grazie! L'output extra su STDERR mi fa sempre sentire un po 'a disagio, ma immagino che dovrei correre con esso.
Trauma digitale

6

R , 360 byte

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

Provalo online!

Non è esattamente la soluzione più elegante. R ha una caratteristica ordinata in cui stdinreindirizzerà al file sorgente, in modo da poter inserire (piccoli) set di dati nel codice sorgente, salvando i byte per la suddivisione delle stringhe o peggio, costruendo il vettore stesso (tutte quelle citazioni si sommano in fretta). Insieme ai built-in per il campionamento casuale, questo fa una risposta breve.


6

Carbone , 203 184 byte

‽⪪”}∨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&”¶

Provalo online! Il collegamento è alla versione dettagliata del codice. Modifica: salvato 19 byte minuscole tutto. Spiegazione:

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

5

Retina , 333 331 321 byte


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?`

Provalo online! Modifica: doubtho salvato 1 byte comprimendo e 1 byte minuscole tutto per poterlo comprimere reply. Quindi ho salvato 10 byte usando il golfista Retina Kolmogorov di @ Leo sul testo minuscolo (che per coincidenza è il numero di byte che ha salvato sulla mia risposta a 333 byte).



@Leo Nota che Retina 0.8.2 è una lingua diversa
mbomb007

@ mbomb007 Lo so, ma per sostituzioni semplici come queste ha la stessa sintassi di Retina 1.0. Stavo solo sottolineando che il golfista Kolmogorov era stato scritto per una versione precedente di Retina, ma è ancora utilizzabile in questo caso.
Leo

4

Cocco , 380 byte

Coconut porto di totallyhuman 's risposta

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('.'))

Provalo online!


4

T-SQL, 393 byte

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()

La funzione STRING_SPLITè disponibile solo in SQL 2016 e versioni successive.

Il migliore che potessi ottenere per le versioni precedenti usando VALUES('It is certain'),('It is decidedly so'),...era 464 caratteri.

Formattato, solo così puoi vedere la parte funzionante:

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

NEWID() genera un nuovo GUID pseudo-casuale, quindi è un modo per fare un ordinamento pseudo-casuale.


4

Gelatina , 201 byte

-2 byte grazie a Mr. Xcoder. -1 byte grazie a 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

Provalo online!

Accidenti , la compressione di SOGL è buona.



201 byte . Basta aggiungere gli ultimi 2 caratteri.
user202729

(Voglio dire, aggiungi ỴXalla fine del codice in modo che scelga casualmente da uno di essi)
user202729

4

05AB1E , 171 byte

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

Provalo online!

Spiegazione

“ ... “invia una stringa di tutte le parole richieste.
Alcune parole sono prese direttamente dal dizionario 05ab1e.
Alcuni sono scritti in ascii (come haze) semplici .
Alcuni sono dizionario combinato e ascii (come do+ n't).

Quindi il codice di elaborazione è:

#                 # 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

Provalo online! - 176 con conversione bruteforce.
Magic Octopus Urn

1
@MagicOctopusUrn: penso che sia 182 con ,e 'aggiunto.
Emigna,

D'oh! Ah, lo vedo, sì. A proposito, rimuovi l'input dal tuo TIO, è un po 'confuso.
Magic Octopus Urn

@MagicOctopusUrn: Doh! Grazie. Non sapevo di averlo lasciato lì: P
Emigna,

166: TIO . Tre volte -1 di utilizzare nuove parole del dizionario ( ye, don, e ha), e -2 dalla ordinare l'elenco per il conteggio delle parole e usando la compressione delta.
Grimmy,

4

Rubino, 362 361 byte

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

Provalo online!

  • 1 byte grazie a @ benj2240

Puoi radere via un byte con ?.invece di '.'.
benj2240

@ benj2240 wow, non l'avevo mai visto prima. Molto bello.
BigRon

1
Ho dovuto cercare la documentazione su quella ?stringa di caratteri singoli letterale
BigRon

3

Python 3, 386 byte

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(';'))

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])

2
Ho trovato un bug. Non è possibile utilizzare virgola come separatore perché 1 delle possibili risposte dal Magic 8-ball contiene una virgola: As I see it, yes.
g4v3,

1
Suggerirei di usare una singola cifra come separatore. Si risparmierebbe 1 byte, poiché le virgolette non sono più necessarie, ma è comunque necessario aggiungere uno spazio per separare la cifra e split.
g4v3,

1
Inoltre, è possibile omettere la parentesi per printe salvare 1 byte in più. Basta mettere un segno più unario prima dell'elenco: print((0..9)[5])diventerebbe print+(0..9)[5].
g4v3,

3

05AB1E , 208 217 byte

"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¡Ω

Provalo online!

Soluzione piuttosto semplice. Le possibili risposte vengono concatenate con il carattere x (poiché non è presente nelle risposte) e quindi compresse (all'interno di ), 'x¡Ω split on x and pop a random choice.

Grazie a @Emigna per aver sottolineato che la compressione dell'alfabeto non piace 'o, molto. Risolto sostituendo la stringa compressa con don ' e , sì .


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

@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

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.


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

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

@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

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

2
You 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

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!


1
Use bitwise OR instead of Math.floor() to save 7 bytes: Math.random()*20|0.
Shaggy

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.


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

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

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

That's true, I'll post an update later today.
rael_kid

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!

2
Surely you can use String.split() to save a bunch of bytes — docs.oracle.com/javase/7/docs/api/java/lang/…
AdmBorkBork

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

2
There's an extra space in your answer and in @KevinCruijssen's golf: use Don't instead of Don' t.
Olivier Grégoire

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.


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...


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


without the -l flag might look more interesting.
Laura Bostan

@LauraBostan But I don't know hilbert curves past type 3
drham

and it's more bytes for all of the \n
drham

1
But yes it would look more 'interesting' per se
drham

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

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.


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

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


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

I must be terribly unlucky then D:
Nathanael C.

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

I keep getting "It is certain" even after with a CTRL+R to hard refresh... I don't get it :x
Nathanael C.

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

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


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

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)

-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

Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.