Shortest code to print ':)' random times

5

1

You have to create a code which prints

:)  

a random number of times from 1 to 255 inclusive. Your output may not contain any whitespace.

Your score :
The count in bytes

EDIT : Also show 3 outputs of your code

Mukul Kumar

Posted 2014-03-06T02:39:29.907

Reputation: 2 585

Question was closed 2016-05-16T06:41:20.463

I would mark it as "Not a duplicate" if I could! – sergiol – 2017-01-16T23:54:10.617

22What's the purpose of subtracting points from popular answers? – sortfiend – 2014-03-06T04:41:57.770

2@sortfiend These challenges are typically scored in terms of how long your answer is, with shorter being better. Thus you want the lowest score possible. That should be stated in the question, though. – Chris Hayes – 2014-03-06T04:53:57.547

24But, further, why is a code golf question scoring based on votes? It's code golf, not a popularity contest – doppelgreener – 2014-03-06T08:38:39.877

8Can you define "random"? Do you mean a uniform distribution between 0 and 255 number of occurrences, any probability distribution where each number of occurences between 0 and 255 has a non-zero probability, or just an unpredictable amount of smileys? – Bakuriu – 2014-03-06T10:27:47.750

1Are quotes ("") allowed in the output? i.e. ":)" versus just :) – Gaffi – 2014-03-06T12:16:31.237

16My php solution is 0 bytes. It is an empty php file. Since you didn't specify what "random" means: For my custom made random number generator, I chose the distribution which gives zero with probability 1 and all other numbers with 0 probability (the degenerate distribution). I am sure you will find it obeys all of your rules. – Tim Seguine – 2014-03-06T14:10:44.347

4-1 for non-code golf scoring when it's tagged code-golf – durron597 – 2014-03-06T14:19:28.987

2Why does this have upvotes, people? Even if you fix the spec. The "challenge" is: generate a random number. Wooooooo! That was hard. And so much fun! I mean it's not like they teach that the first day of every programming class ever. – Tim Seguine – 2014-03-06T14:26:16.057

7I agree with @TimSeguine, if I could I would downvote. This is super easy, basically no option to be creative in any way, strange score system (mix of code-golf and popularity), the challenge itself isn't very innovativ. – print x div 0 – 2014-03-06T15:09:31.223

@AndroidRookie should I delete this post ? – Mukul Kumar – 2014-03-06T17:32:55.953

@TimSeguine The idea is not just to create a random number, but also to print a string that many times. There are enough ways to go about this (print N times, multiply the string by N, etc) to warrant golfing it, even if the end result is small expressions in every language that fit cleanly into two or three categories of type of solution. If I could upvote the ingenuity that went into the Befunge solution more than once, for example, I would. – algorithmshark – 2014-03-06T17:47:28.053

@algorithmshark yeah, I understood the challenge, generate a random number and display it in unary. Still not interesting. – Tim Seguine – 2014-03-06T18:50:25.297

@MukulKumar No, you shouldn't delete this post. I think you can't delete it since it has upvoted answers. – Tim Seguine – 2014-03-06T19:04:00.457

1

@ALL who don't think it's a challenge ! This question is NOT a code-challenge but a code-golf. You don't have to Face challenges but To make the code shortest possible ! If you want challenge then there are other questions! solve those and don't waste your time here debating! If you have any confusion regarding WHAT IS CODE-GOLF then visit here http://codegolf.stackexchange.com/tags/code-golf/info

– Mukul Kumar – 2014-03-07T02:24:00.737

Python in 22 on the second page. If you are going to abuse the idea of "random", at least do it right! http://codegolf.stackexchange.com/a/23308/8777

– None – 2014-03-07T05:09:08.063

2@MukulKumar the word "challenge" has an English meaning independent of the site. Everyone understands that this is a code golf. – Tim Seguine – 2014-03-07T10:01:20.053

Has anyone linked to that xkcd about random number generators yet? – AakashM – 2014-03-07T15:19:08.467

2

@AakashM Yes.

– The Guy with The Hat – 2014-03-08T13:47:09.517

I don't get why this question has 57 answers, almost 6k views and only 6 upvotes. – Vereos – 2014-03-09T13:21:15.430

@Vereos Well I don't know it either ;[ – Mukul Kumar – 2014-03-09T13:25:28.880

In [tag:code-golf]'s wiki excerpt: "A competition which scores on a mixture of source length and some other criterion should be tagged [tag:code-challenge] instead.". @sortfiend Presumably it's lowest score wins, which is a common scoring system on this site. – Dukeling – 2014-03-09T14:28:29.897

@Vereos The lack of upvotes could be explained by reading the comments. – Dukeling – 2014-03-09T14:29:47.497

@Dukeling I did, but, if everyone keeps answering it (and following it), I don't get why they shouldn't upvote it too. My 2 cents. – Vereos – 2014-03-09T14:32:12.060

@Dukeling I edited the question Now is it fine ? – Mukul Kumar – 2014-03-09T14:41:23.840

@Vereos Just because you're able to answer, or you're interested in an answer (by the way, no-one favourited this question, not sure what you mean by 'following'), doesn't mean you think it's a good question. And most of the visitors probably got here from the Hot Network Questions, just meaning it might have an attention-drawing title, nothing more. – Dukeling – 2014-03-09T15:28:41.667

Answers

30

GolfScript, 12 characters

":)"256rand*

Nothing really interesting here.

Doorknob

Posted 2014-03-06T02:39:29.907

Reputation: 68 138

I don't know about GolfScript but, I think \n is not needed – Mukul Kumar – 2014-03-06T02:58:41.093

@Mukul But then the output would be :):):):):)... – Doorknob – 2014-03-06T02:59:29.223

No problem with that – Mukul Kumar – 2014-03-06T03:01:19.883

1It doesn't change the length, but shouldn't that be 256 rather than 255? – DocMax – 2014-03-06T05:05:16.467

11@Doorknob Happy 10k! – Digital Trauma – 2014-03-06T05:09:32.163

1@DocMax: If we want a uniform distribution from 0 to 255 inclusive, yes. If not, it might as well be 9. :) – Ilmari Karonen – 2014-03-06T09:05:30.800

@DocMax You're right, fixed! – Doorknob – 2014-03-06T12:51:04.140

@Doorknob Even if you wanted to do the newlines between the :), you shouldn't have used \n; you should have used ':) newline '. – Justin – 2014-03-06T20:53:39.177

7Why in the world does this answer have so many upvotes? There are other more interesting answers out there. – Justin – 2014-03-06T21:05:23.850

It does not even display three outputs of the code. – Mikaël Mayer – 2014-03-08T23:29:30.543

4@Quincunx to point out how uninteresting this problem is. A good code-golf question should not be solvable by boring answers. If it is, it's a bad question. – o0'. – 2014-03-09T00:32:37.267

54

JavaScript (ES6), 25

":)".repeat(new Date%256)

Outputs (REPL):

> ":)".repeat(new Date%256)
":):):):):)"
> ":)".repeat(new Date%256)
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"
> ":)".repeat(new Date%256)
":):):):):):):):):):):):):):):):):):):):):):):):):):):)"

Florent

Posted 2014-03-06T02:39:29.907

Reputation: 2 557

2You sir deserve more likes! – Silviu Burcea – 2014-03-06T10:48:38.430

that ain't random sir – rafaelcastrocouto – 2014-03-06T17:21:38.153

5@rafaelcastrocouto The question does not mention about how good the random generation must be. Using the timestamp seems to be a good compromise between number distribution and randomness. – Florent – 2014-03-06T17:44:07.510

3You can use new Date%256, instead of Date.now()%256. 2 characters shorter. – Toothbrush – 2014-03-06T19:11:04.633

4@rafaelcastrocouto It takes a random seed (The time at which you choose to run it), it's predictable (like any RNG) because you know the seed, still random. – George Reith – 2014-03-07T00:01:56.077

I think using repeat is cheating. It's a proposed part of ES6 and only supported on Firefox. – Stephen Melvin – 2014-03-07T15:40:14.047

1@Steve most golfing languages are never used in production, at least ES6 will actually be used. – howderek – 2014-03-07T20:08:50.120

1@howderek On this page I see Javascript, Scala, Bash, Ruby, Python, and C. I would say that most are definitely used in production. My complaint was that the method used wasn't even part of the language. – Stephen Melvin – 2014-03-07T22:15:55.067

@Steve repeat is supported by Chrome (and v8) with harmony flag. Moreover repeat specification is approved by the ES6 committee. – Florent – 2014-03-08T08:39:08.017

@rafaelcastrocouto: It's reasonably random. In JavaScript, new Date gives time in milliseconds. Every single value can be received, and I doubt you could run program quickly enough to have the same millisecond. – Konrad Borowski – 2014-03-09T08:25:20.283

ok you guys convinced me! by the way ... the repeat method: String.prototype.repeat = function(n){s=this;while(--n)s+=this;return s} – rafaelcastrocouto – 2014-03-09T11:44:07.300

1@rafaelcastrocouto You mean String.prototype.repeat = function(n){var s=this;while(--n)s+=this;return s}? – Toothbrush – 2014-03-09T13:11:57.233

that's less lazy! – rafaelcastrocouto – 2014-03-09T13:27:12.350

33

C - 116 (including artistic whitespace)

  x,i;           main
  (){           srand
         (time
         (0));
for                   (x=
 rand()            %256;
   i<x;           i++)
      printf(":)");}

I never get to do ASCII art code, and the 65 needed characters in the code are already running long as is... This was actually harder than I thought it would be because of the small number of characters to work with and the density of the code. Gets the point across at least.

Boring version:

x,i;main(){srand(time(0));for(x=rand()%256;i<x;i++)printf(":)");}

Note - Auto code counts are going to be off because I had to replace 8 tabs with spaces to get it to look the same in the code window. You can verify my count here if you want.

Edit: Oops, forgot to post output (newlines added for legibility).

comintern@fidel ~ $ ./a.out 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):)
comintern@fidel ~ $ ./a.out 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
comintern@fidel ~ $ ./a.out 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):)

Comintern

Posted 2014-03-06T02:39:29.907

Reputation: 3 632

don't we include files like stdlib.h or so and count their char count ? – Mukul Kumar – 2014-03-06T05:55:27.303

It compiles without headers in gcc. It complains about implicit declaration of built-in function ‘printf’, but works fine. – Comintern – 2014-03-06T06:01:36.997

You could drop 1 character by doing for(x=rand()%256;i++<x;). EDIT: But it would break your ASCII art, yeah. – Maxime Lorant – 2014-03-08T10:00:33.987

This can be done with just 60 chars: x;main(){srand(time(0));for(x=rand()%256;--x;)printf(":)");}.

– Tobias – 2014-03-08T11:15:14.377

@still_learning - Yeah, I know it can be quite a bit shorter, I structured the loop that way to keep the long strings I could divide distributed right. – Comintern – 2014-03-09T01:24:52.153

29

Scala REPL 1337

Scala makes everyone happy. Need 266 votes to lower the score.

("""
:^)  :^(  :^[  :^]  :^D  :^P  :^b  :^&  
:o)  :o(  :o[  :o]  :oD  :oP  :ob  :o&  
:O)  :O(  :O[  :O]  :OD  :OP  :Ob  :O&  
:)  :(  :[  :]  :D  :P  :b  :&  
;^)  ;^(  ;^[  ;^]  ;^D  ;^P  ;^b  ;^&  
;o)  ;o(  ;o[  ;o]  ;oD  ;oP  ;ob  ;o&  
;O)  ;O(  ;O[  ;O]  ;OD  ;OP  ;Ob  ;O&  
;)  ;(  ;[  ;]  ;D  ;P  ;b  ;&  
=^)  =^(  =^[  =^]  =^D  =^P  =^b  =^&  
=o)  =o(  =o[  =o]  =oD  =oP  =ob  =o&  
=O)  =O(  =O[  =O]  =OD  =OP  =Ob  =O&  
=)  =(  =[  =]  =D  =P  =b  =&  
8^)  8^(  8^[  8^]  8^D  8^P  8^b  8^&  
8o)  8o(  8o[  8o]  8oD  8oP  8ob  8o&  
8O)  8O(  8O[  8O]  8OD  8OP  8Ob  8O&  
8)  8(  8[  8]  8D  8P  8b  8&  
B^)  B^(  B^[  B^]  B^D  B^P  B^b  B^&  
Bo)  Bo(  Bo[  Bo]  BoD  BoP  Bob  Bo&  
BO)  BO(  BO[  BO]  BOD  BOP  BOb  BO&  
B)  B(  B[  B]  BD  BP  Bb  B&  
%^)  %^(  %^[  %^]  %^D  %^P  %^b  %^&  
%o)  %o(  %o[  %o]  %oD  %oP  %ob  %o&  
%O)  %O(  %O[  %O]  %OD  %OP  %Ob  %O&  
%)  %(  %[  %]  %D  %P  %b  %&  
@^)  @^(  @^[  @^]  @^D  @^P  @^b  @^&  
@o)  @o(  @o[  @o]  @oD  @oP  @ob  @o&  
@O)  @O(  @O[  @O]  @OD  @OP  @Ob  @O&  
@)  @(  @[  @]  @D  @P  @b  @&  
X^)  X^(  X^[  X^]  X^D  X^P  X^b  X^&  
Xo)  Xo(  Xo[  Xo]  XoD  XoP  Xob  Xo&  
XO)  XO(  XO[  XO]  XOD  XOP  XOb  XO&  
X)  X(  X[  X]  XD  XP  Xb X&
^__^
""".replaceAll("\n","").replaceAll("x|X",":)")
.replaceAll("(:|=|8|B|;|%|@)+",":")
.replaceAll("[^:]+","\\)")
.substring(0,new scala.util.Random().nextInt(256)*2))

Output 1

res32: String = :)

Output 2

res33: String = 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):)

Output 3

res34: String = 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

FYI, the code to generate all smileys is the following:

for(i <- ":;=8B%@X"; j <- "^oO".toIterator.map(_.toString) ++ List(""); k <- ")([]DPb&") yield (i.toString+j.toString+k.toString)
//         eyes          nose or nothing                                      mouth

Mikaël Mayer

Posted 2014-03-06T02:39:29.907

Reputation: 1 765

2Add 5 more bytes and you have my vote :) – Justin – 2014-03-06T18:54:32.403

1Did it. Added a chinese smiley: ^^ . Now because your comment has been upvoted once, there should be two more people voting for my answer ^^ – Mikaël Mayer – 2014-03-07T15:11:15.483

17

Python 23

print':)'*(id(9)/8%256)

Demo

D:\temp>smiley.py
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):)

D:\temp>smiley.py
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):)

D:\temp>smiley.py
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):)

Abhijit

Posted 2014-03-06T02:39:29.907

Reputation: 2 841

id(9) is not random and id(9)%255 will never give 255. – grc – 2014-03-06T05:00:14.860

2@grc: id(9) is random across multiple sessions but not across the same session. To get a random number across Please refer my output :-). And I agree, it should be id(9)%256 – Abhijit – 2014-03-06T05:44:22.593

It appears to me that the output of id is always divisible by 8, so only 32 unique numbers can be produced from id(x)%256. If you divide by 8 first it should fix this. – grc – 2014-03-06T06:00:08.880

@grc: Ahh yes, I forgot about that, yet thought that implementation dependent, yet in cPython which is widely used, its how its implemented – Abhijit – 2014-03-06T06:08:53.070

@downvoter: Can you please explain what is wrong with the code and how it can be corrected? – Abhijit – 2014-03-06T06:09:54.620

@Abhijit Drop the print. It is not needed in REPL. – thefourtheye – 2014-03-07T08:46:10.633

@thefourtheye: In that case it may not be a code but a statement. Also, I would want it to run as a script rather than in REPL. – Abhijit – 2014-03-07T08:50:24.533

1@Abhijit: You can shave off one more character by swapping the multiplication around, since then you can get rid of the parenthesis (but have to add the space after print): print id(9)/8%256*':)' :) – Aleksi Torhamo – 2014-03-10T00:59:46.577

13

Java 72 lines 1,832 bytes and ~50 seconds runtime

Me and my buddy pair programmed (Agile Methods ftw) this golfed Java Enterprise solution.

import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;

public class EnterpriseJavaSolution {

    public static class BodyPart {

        private char[] part = new char[2];

        public BodyPart (String part) {
            this.part = part.toCharArray();
        }

        public String toString() {
            return new String(part);
        }

    }

    public static class Eyes extends BodyPart {

        public Eyes () {
            super(":");
        }

    }

    public static class Mouth extends BodyPart {

        public Mouth () {
            super(")");
        }

    }

    public static class Face extends BodyPart {

        /**
         * So generic, much parts
         */
        public Face (List<BodyPart> parts) {
            super(parts.toString());
        }

    }

    public static void main (String[] args) {

        SecureRandom seed = new SecureRandom();
        //Very random, dont use all RAM though!!
        SecureRandom reallyRandom = new SecureRandom(seed.generateSeed((int) (Runtime.getRuntime().maxMemory() / 2.0)));
        byte[] randomNumber = new byte[1];
        reallyRandom.nextBytes(randomNumber);
        ArrayList<Face> smilees = new ArrayList<Face>();

        //Why are Java bytes signed! Such inconvenience
        for (int numSmilee = 0; numSmilee <= Math.abs(randomNumber[0] * 2.0); numSmilee++) {
            ArrayList<BodyPart> bits = new ArrayList<BodyPart>(new Integer((int)2.0)); //Optimal
            bits.add(new Eyes());
            bits.add(new Mouth());
            smilees.add(new Face(bits));
        }

        //TODO: make N-tier solution for printing
        System.out.println(smilees.toString().replaceAll("[^:)]",""));

    }

}

I've timed the runtime and given some example output below. I'm satisfied at the production readiness of this code.

$ time java EnterpriseJavaSolution
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

real    0m53.678s
user    0m4.380s
 sys    0m48.568s

$ time java EnterpriseJavaSolution
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

real    0m51.928s
user    0m4.218s
 sys    0m46.704s

$ time java EnterpriseJavaSolution
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

real    0m55.480s
user    0m4.074s
 sys    0m50.621s

Matt Oates

Posted 2014-03-06T02:39:29.907

Reputation: 298

This made me burst out laughing :D – Beta Decay – 2015-08-27T12:28:53.197

1The real joke is we both program in Perl professionally :) – Matt Oates – 2015-08-28T18:28:29.260

The question is a [tag:code-golf], so please include the character count in your answer. Also, try to "golf" your answer by removing unnecessary whitespace for example. And I also think that this answer can be a lot shorter, so for example it is not really necessary to create a class for each part of the smiley. It might be a good programming practice, but this is code-golf, code length is a lot more important than best practices. – ProgramFOX – 2014-03-07T18:42:05.113

3Well the previous Java example was critiqued for bad practice and lack of randomosity >:3 – Matt Oates – 2014-03-07T20:25:45.317

Haha I love this. Needs more comments and java doc though. – krs013 – 2014-05-20T05:17:22.353

12

PowerShell 21, 17

":)"*(Random 256)

PS C:\Users\DocMax> ":)"*(Random 256) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

PS C:\Users\DocMax> ":)"*(Random 256) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

PS C:\Users\DocMax> ":)"*(Random 256) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Edit: Removed Get- following Rynant's awesome news-to-me input. It's not often that PowerShell is competitive at code golf.

DocMax

Posted 2014-03-06T02:39:29.907

Reputation: 704

1All Get-<Something> functions in PowerShell are automatically aliased as <Something>, so you can save 4 bytes by getting rid of Get- – Rynant – 2014-05-12T18:36:26.797

1

I really want to make this shorter, but it's so simple I'm afraid that's not possible. Fair warning about omitting "Get-": It's fine for short scripts like this, but it actually bloats the run time quite significantly. Try Measure-Command {Get-Random}; Measure-Command {Random} to see the difference. On my system, they're 0.1579 ms vs. 30.0963 ms. It's hardly noticeable when you're just running it once, but it can be a big deal when your script uses the command a lot more (say, 30,000 times)!

– Iszi – 2014-05-27T15:26:48.280

Thanks for the comment on aliasing. It's always useful to know the potential impact of something like aliasing, even when it is small. – DocMax – 2014-05-27T16:45:27.273

11

C 50 48 44 (with the suggestion from @urogen and @n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳)

Note I liked what @Comintern, so tried to do something similar with my answer

/*
Uninitialized c will always randomized to an address range (assuming system 
supports ASLR. 
Recursion instead of loop to reduce code length 
As whitespace is not counted, organized the code to represent a smiley character
*/
main(a
        ,
          c)
  {c       &&  
 main        (    
printf        (
 ":)"        )
  ,(       c&
         255
       )
-1);}

Demo

D:\temp>Smiley.exe
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):)
D:\temp>Smiley.exe
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):)
D:\temp>Smiley.exe
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):)

IDEONE

http://ideone.com/ZWPjqS

Abhijit

Posted 2014-03-06T02:39:29.907

Reputation: 2 841

I get a segmentation fault about half the time. I suppose it is intentional that you are trying to get a "random" variable by not initializing c? – skibrianski – 2014-03-06T04:47:15.500

@skibrianski: Yes, there was some issue with the code. Brackets were misplaced and we need to work with absolute value – Abhijit – 2014-03-06T05:53:18.640

Have you tried (c&0xff) instead of abs(c)%256? This should work due to integer promotion. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-03-06T06:48:16.093

c&&main(printf(..),..); would be shorter. – ugoren – 2014-03-06T06:51:10.290

I think you missed urogen's other suggestion, to move the printf to main's arguments. – hvd – 2014-03-06T13:24:07.760

Even shorter (38): main(a,c){while(c--%256)printf(":)");} – TwoThe – 2014-03-08T13:11:16.643

11

Befunge 98 - 20 bytes (with unicode)

?1+:'ÿ`!j@"):",,>
@

? sends the IP in a random direction, either left, right, up, or down. After doing so, I increment a counter and compare it to 255: 1+:'ÿ`!. j@ will exit if this is the 256th time. "):" is the frowny face that I'm supposed to print, and ,, prints it (output: :)). The > is to ensure that if the IP goes left, it will change directions and go right.

On each iteration, there is a 2/3 probability that the loop will exit. This means that the probability that comparing to 255 is needed (assuming perfect random) is

(1/3)255 = 1/46336150792381577588313262263220434371406283602843045997201608143345357543255478647000589718036536507270555180182966478507

Is that close enough to zero to justify not comparing to 255 (it would save me 10 bytes, bringing me down to 10 bytes)? For comparison, this number is about 2.158 × 10-122. The number of atoms in the universe is about 1080. The Planck length, the smallest measurable length (as in the universe does not allow for smaller), is 1.616199(97) × 10-35 m. This means that if this number were the size of the Planck length, the Planck length would be about

8.5×1059 × diameter of the observable universe (93 billion light-years)

First output:

:)

Second output:

:):)

Third output:

:):):):):)

Alternatively, if I am allowed to print null characters, then this works, for 19 bytes:

?,,":)"_@#-ÿ':+1
@

Exploit (you say random times in the range 0-255, so I'll choose random in the range 0-126, saving 1 more byte):

?1+:'~`!j@"):",,>
@

Justin

Posted 2014-03-06T02:39:29.907

Reputation: 19 757

3+1 for noticing that the random distribution need not be uniform. – imallett – 2014-03-06T07:14:39.673

8

J - 18 char

Surprisingly, there is a subtle behaviour in the J interpreter that prevents a quick 12 character solution: the interpreter's REPL output is truncated after 256 characters, so you have to print directly to stdout to "do it right".

1!:2&4^:(?256)':)'

Explained:

  • 1!:2&4 - Print to stdout (file handle 4)...
  • ^:(?256) - ... a random number of times less than 256...
  • ':)' - ... the string :).

Examples:

   1!:2&4^:(?256)':)'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
   1!:2&4^:(?256)':)'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
   1!:2&4^:(?256)':)'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

And, for posterity, here's the 12 char solution which generates the string but is unable to display it right.

':)'$~2*?256

We take the random int, multiply it by 2, and then create a string that long, cyclically pulling characters from :). Yes, this is shorter than copying the string.

algorithmshark

Posted 2014-03-06T02:39:29.907

Reputation: 8 144

Which one should I consider...18 char or 12 char solution – Mukul Kumar – 2014-03-06T03:38:44.420

1The 12 char version doesn't print the string properly whenever the random number is 129 or greater, due to the nature of the J interpreter. Unless the rules change, only the 18 char solution is correct. – algorithmshark – 2014-03-06T03:57:08.970

1

You can double the max line length with (9!:37) 0 512 0 222. I'm not sure whether setting global parameters is allowed outside of the character count though.

– grc – 2014-03-06T05:09:33.220

Assuming the z locale, you can get 17 with echo(+:?128)$':)' – AlliedEnvy – 2014-03-07T01:04:44.983

@AlliedEnvy You could get even shorter with echo':)'$~+:?256 (16 char), but it falls prey to the same bug as above, because echo uses 1!:2&2 and not &4, and thus respects the settings in 9!:36. – algorithmshark – 2014-03-07T01:33:07.320

@grc I don't see why not. I have never used J, but I can imagine increasing the maximal line length without the context of this codegolf challenge. – 11684 – 2014-03-09T13:46:22.233

Another 12 char possibility would be this one: ':)'$~2*?256 – ɐɔıʇǝɥʇuʎs – 2014-05-12T19:41:39.773

7

Ruby, 18

(with help from manatwork, David Herrmann, and Victor)

$><<':)'*rand(256)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Greg Jennings

Posted 2014-03-06T02:39:29.907

Reputation: 171

Not sure how to show the wrapping in the result part, but they are of different lengths – Greg Jennings – 2014-03-06T03:38:52.587

1press enter then add four spaces before text – Mukul Kumar – 2014-03-06T03:53:35.800

Shouldn't it be rand(256) to get 0-255? – Victor Stafusa – 2014-03-06T06:15:41.560

You can use spare: 1 character by using $><< to output; 2 characters by removing the outer pair of parenthesis. $><<':)'*rand(255) – manatwork – 2014-03-06T07:44:58.043

What about using p? p':)'*rand(255) – David Herrmann – 2014-03-06T08:15:30.390

Since the number passed to rand(n) is excluded, it should be rand(256) – David Herrmann – 2014-03-06T08:21:25.010

Now your sample outputs are wrong. p outputs quoted strings. – manatwork – 2014-03-06T12:58:12.053

Ah of course you're correct. Change made to your suggested approach. Thanks. – Greg Jennings – 2014-03-06T13:01:45.590

3$><< looks fancy, but is there anything wrong with puts':)'*rand(255)? – Ry- – 2014-03-06T19:53:29.060

7

perl 20, 17 characters

Thanks to skibrianski for shaving 3 characters.

say":)"x rand 256

Sample execution:

$ perl -M5.10.0 -e 'say":)"x rand 256'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):)

$ perl -M5.10.0 -e 'say":)"x rand 256'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):)

$ perl -M5.10.0 -e 'say":)"x rand 256'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):)

$ perl -M5.10.0 -e 'say":)"x rand 256'                                                 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

devnull

Posted 2014-03-06T02:39:29.907

Reputation: 1 591

You can save 2 bytes by: 1 - nuking the space between say and the smiley and 2 - ditching the parens around rand. IOW: 'say":)"x rand 255' – skibrianski – 2014-03-06T04:47:58.300

@skibrianski Indeed. Thanks! – devnull – 2014-03-06T04:55:28.673

note: rand 255 doesn't include 255 – jfs – 2014-03-08T08:39:50.470

@J.F.Sebastian Oversight, I guess. I'll change it to 256. (Between 0 and 255 is ambiguous at best.) – devnull – 2014-03-08T08:42:05.860

could shave off a byte: say":)"x($$&255) (or if you want to be a smartass, say":)"x($^T&255), where ^T is the literal control character) – Eevee – 2014-03-09T19:36:56.140

What's interesting is that this is almost the same as the shortest Perl6 code. The only difference is that Perl6 requires some whitespace after sub calls ( unless you alter the parsing behaviour with a slang or macro ). – Brad Gilbert b2gills – 2014-12-01T14:03:24.277

6

PHP | 30 bytes

 <?=str_repeat(':)',rand()%256)

gvgvgvijayan

Posted 2014-03-06T02:39:29.907

Reputation: 169

Add a '#' character before 'PHP' to make it a heading like other answers – Mukul Kumar – 2014-03-06T04:57:55.133

1Since this question is tagged [tag:code-golf], it is helpful to include the character count in your answer. – grc – 2014-03-06T06:52:22.937

You can remove the space and the mt_ – TimWolla – 2014-03-06T11:20:51.793

4A shorter version: <?=str_repeat(":)",rand()%256); – Florent – 2014-03-06T13:01:39.047

Instead of upvote my answer please upvote @Florent – gvgvgvijayan – 2014-03-06T14:03:14.350

5

Python 2.7 - 45 bytes

print':)'*__import__('random').randint(0,255)

(Originally this printed :)\n, the newline was removed upon OP's clarification)

The (slightly) more idiomatic way to do this is

from random import*
print ':)'*randint(0,255)

which is... also 45 bytes, but I figured "why not make it a one-liner?"

Three sample outputs:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

 

:):):):):):):):):):):):):):):)

 

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

undergroundmonorail

Posted 2014-03-06T02:39:29.907

Reputation: 5 897

I am okay with no newline and white spaces – Mukul Kumar – 2014-03-06T02:51:19.043

Cool, I edited my answer. – undergroundmonorail – 2014-03-06T02:53:29.510

1Actually, I was wrong to begin with. print':)'*(whatever) includes newlines. I didn't test it until right now. I learned something new today! – undergroundmonorail – 2014-03-06T03:00:33.053

...No, that's a lie. I took out the \n from my answer here and didn't take it out on my local copy. Never mind. – undergroundmonorail – 2014-03-06T03:02:12.433

3I think you can save up to 7 characters by using os.urandom instead. – grc – 2014-03-06T04:51:28.830

1What grc means is: import os;print':)'*ord(os.urandom(1)) – Justin – 2014-03-06T07:04:15.547

You don't need the print either, since it doesn't specify the output; the console buffer is sufficient leading to only ':)'*__import__('random').randint(0,255) which is 41 characters in length or only 38 when using the code suggested by @grc: ':)'*ord(__import__('os').urandom(1)) – aodj – 2014-03-06T11:00:57.613

1@alexander shorter than that would be: import os;':)'*ord(os.urandom(1)) at 33 chars – Justin – 2014-03-06T21:04:26.467

5

Mathematica 35

Row@Table[":)", {RandomInteger@255}]

Examples

outputs

DavidC

Posted 2014-03-06T02:39:29.907

Reputation: 24 524

5

Pure Bash, 41

printf -va %$[RANDOM>>7]s;echo ${a// /:)}

Sample outputs:

$ printf -va %$[RANDOM>>7]s;echo ${a// /:)}
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
$ printf -va %$[RANDOM>>7]s;echo ${a// /:)}
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
$ printf -va %$[RANDOM>>7]s;echo ${a// /:)}
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
$ 

Digital Trauma

Posted 2014-03-06T02:39:29.907

Reputation: 64 644

5

APL: 12 characters

(?255)⍴⊂':)'

In this code, ?255 generates a random number between 1 and 255. The function repeats the argument to the right this number of times. The expression ⊂':)' encpsulates the string :) into a single object, since otherwise the expression 3⍴':)' would yield :): as opposed to :) :) :).

Edit: The behaviour of this function depends on the value of ⎕IO. If it's set to 0 (the default in many versions of APL) then ?255 will return a value in the range 0-254. If it is 1, the return value with be in the range 1-255.

Elias Mårtenson

Posted 2014-03-06T02:39:29.907

Reputation: 209

1Wrong answer on two counts: It prints lots of forbidden white-space, and the number should be 256. – Adám – 2015-10-15T21:29:58.510

range is 0-255 not 1-255 – Mukul Kumar – 2014-03-06T05:27:08.830

Fair enough. If you set ⎕IO to 0 (which is the default in many versions of APL), that will be the effect. – Elias Mårtenson – 2014-03-06T05:28:14.530

well, you can have numbers from 1-256 then subtract 1 from it – Mukul Kumar – 2014-03-06T05:29:40.417

5

Python - 21

The randomness is stretching the rules a fair bit, but each run will probably be different.

print':)'*(id(1)%255)

And some example runs:

> python -c "print ':)'*(id(1)%255)"
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
> python -c "print ':)'*(id(1)%255)"
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
> python -c "print ':)'*(id(1)%255)"
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

user8777

Posted 2014-03-06T02:39:29.907

Reputation:

print id(1)%255*":)" would be one byte shorter. – Jonathan Frech – 2017-10-02T12:06:04.803

4

Javascript - 51 characters

Thanks to @grc and @DocMax for shaving 3 characters.

for(i=0|Math.random(t='')*256;i--;)t+=':)';alert(t)

4 Outputs:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Victor Stafusa

Posted 2014-03-06T02:39:29.907

Reputation: 8 612

1You don't need to convert i to an int immediately. Using a condition like ~~i-- or --i>0 should save 2 chars. You can also save a char with Math.random(t=''). – grc – 2014-03-06T04:39:17.943

1Intead of ~~() save 2 with 0|Math.... And another if you move t='' inside of the random() call – DocMax – 2014-03-06T04:45:06.120

Just as a curiosity, this is the Harmony version, currently working only in Firefox: alert(':)'.repeat(Math.random()*256)). – manatwork – 2014-03-06T07:49:43.093

@manatwork Didn't knew that the repeat method exists (experimental for now, but exists). Anyway, I think that you may post an entirely new answer by yourself for this. I will upvote it. – Victor Stafusa – 2014-03-06T08:09:09.447

@Victor It’s new in ES6. Here’s a fully spec-compliant polyfill for it: http://mths.be/repeat

– Mathias Bynens – 2014-03-06T14:54:42.773

4

Groovy (37 29 characters, @Michaël Demey's suggestion)

print":)"*(Math.random()*255)

The initial solution was:

print":)"*(new Random().nextInt(256))

0x2D9A3

Posted 2014-03-06T02:39:29.907

Reputation: 141

2I brought it to 29 characters: print":)"(Math.random()255) – Michaël Demey – 2014-03-07T11:59:25.763

4

R, 34

cat(rep(":)",runif(1)*256),sep="")

Sven Hohenstein

Posted 2014-03-06T02:39:29.907

Reputation: 2 464

You can probably leave off cat and beat the answer I just posted. ;-) – Gaffi – 2014-03-06T12:12:10.540

@Gaffi The output should contain :) only. – Sven Hohenstein – 2014-03-06T12:13:19.813

Well, I guess that's up to interpretation! Adding a comment to the original question. – Gaffi – 2014-03-06T12:15:42.993

@Gaffi The default is sep = " ". – Sven Hohenstein – 2014-03-06T12:18:53.793

1@Gaffi Let me cite the OP: *No white-space*. – Sven Hohenstein – 2014-03-06T12:25:21.920

You are correct! I read that (for some bizarre reason) as part of the scoring. – Gaffi – 2014-03-06T12:26:39.447

1It should be cat(rep(":)",runif(1)*256),sep=""), otherwise you will never get 255 smilies. See length(rep(":)",254.9999)). – djhurio – 2014-03-08T12:16:33.453

1@djhurio Thanks, good point! – Sven Hohenstein – 2014-03-08T12:52:22.380

4

Pure ZSH - 32

repeat $[RANDOM%256] echo ":)\c"

Output 1:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output 2:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Soheil Hassas Yeganeh

Posted 2014-03-06T02:39:29.907

Reputation: 141

3

C++ 104 84 107

#include<iostream>
int main(){int *a=new int;a+=2;*a%=256;std::cout<<*a;while(*a-->0)std::cout<<":)";}  

:( I think I'll never beat other languages in golfing !
Anyway...OUTPUT

#1

:):):):):):):):):):):):):):):):):):):):):):)  

#2

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

#3

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Mukul Kumar

Posted 2014-03-06T02:39:29.907

Reputation: 2 585

fake output? on my machine it always prints the same number of smileys – izabera – 2014-03-06T09:07:05.043

btw you could save a few char with while(*a--%256) – izabera – 2014-03-06T09:07:25.073

@izabera try it again ! – Mukul Kumar – 2014-03-06T17:42:06.530

3

(PHP/Python/Perl/Javascript/others)-Polyglot - 0 bytes



Output 1:

Output 2:

Output 3:

You never specified a distribution for the random variable denoting the number of times, so this outputs from the degenerate one with the entire mass on zero. This is fine under the definition of range where it is equal to the codomain of a function, rather than its image.

Alright, it's a huge cheat, but since the id(9) code was successful despite not being guaranteed uniform, I figured this isn't entirely unclever.

Also compiles in C under some compilers. See discussion here.

Yonatan N

Posted 2014-03-06T02:39:29.907

Reputation: 497

Well the random number you choose is 0 all the time therefore I should not consider this as a correct answer ! edit or delete your post – Mukul Kumar – 2014-03-06T04:54:19.120

1I recommend you edit your post if you want a uniform distribution. As of now, this answer is mathematically perfectly correct. – Yonatan N – 2014-03-06T04:57:48.493

I asked for a random number! not intentional number or any constants. Intentionally this has 0 all the time! Also random-number is a number which we cannot predict(it may repeat) – Mukul Kumar – 2014-03-06T05:00:07.393

1

Which is still random. I recommend you familiarize yourself with the content of the first link I provided in the post, as well as elementary measure theory and the axiomatic definition of randomness that follows. There is nothing preventing Ω from being a singleton.

– Yonatan N – 2014-03-06T05:04:22.283

Go to this site and read 1st para http://whatis.techtarget.com/definition/random-numbers

– Mukul Kumar – 2014-03-06T05:07:08.603

2Well, you can lead a horse to water, but you can't make him learn measure theory. – Yonatan N – 2014-03-06T05:08:24.207

1

Oh, come now. This is a wet blanket answer and you know it. No amount of advanced maths study will enable a troll to change his horns. :) Also, as evidenced by your own "discussion here" link, this gag was already tired in 1994.

– Jonathan Van Matre – 2014-03-06T05:56:37.067

4I'd argue that there's a difference between finding a loophole in the rules and intentionally syntactically misparsing them, but it's not my job to not submit troll answers when the question is practically begging for them. Downvotes, ahoy! – Yonatan N – 2014-03-06T06:20:16.750

3+1 This is a perfectly reasonable interpretation of the question. The OP didn't specify the distribution. The degenerate distribution is a perfectly valid choice, no more incorrect than a uniform distribution. It may be a tired gag, but I am tied of "underspecified challenges". Make a challenge that is worth solving and nobody will post joke answers. – Tim Seguine – 2014-03-06T14:18:27.733

3@JonathanVanMatre This isn't interpreting the challenge too literally. It is not our fault if the OP doesn't know what random means. – Tim Seguine – 2014-03-06T14:23:33.450

1

@MukulKumar I have a better reference for you: http://math.umn.edu/~isakema/docs/FM5011/Probability%20Spaces.pdf if you want a uniform distribution you have to specify that. Also Here's news for you: I guarantee that about 90% of the answers here won't produce randomness according to a uniform distribution(what is described in your link), because most programmers introduce skew.

– Tim Seguine – 2014-03-06T14:32:05.240

"I'd argue"--well it's a good thing you would argue because you're not arguing yet. ;-P Did you consider a more charitable assumption than "OP doesn't know what random means"? Perhaps OP knows that but doesn't know how to rigorously express his/her meaning in English. Every other respondent managed to parse the question and recognize OP's intent. I am confident at least one of them knows as much about measure theory as you two tricksters, but chose to answer the question's spirit instead of its letter. – Jonathan Van Matre – 2014-03-06T15:33:28.450

Finally, if you dislike underspecified challenges, specify a better one. We do need more good content. (And I will in good faith apply the corollary to myself - If you dislike trollish answers, submit a better one.) – Jonathan Van Matre – 2014-03-06T15:36:16.240

3@JonathanVanMatre I have posted 3 challenges since joining this site. At the very least that is three more than you have. ;) And no I think you are wrong: I think it is clear from the comments that the OP in fact doesn't know what he wants. The link he provided implies that he wants a uniform distribution, but he hasn't complained, for example, that the Befunge answer doesn't use a uniform distribution. I stand by my statement that good questions don't attract troll answers. – Tim Seguine – 2014-03-06T19:00:47.727

2The distribution of a random variable is understood to be uniform, when not otherwise specified. – Kaz – 2014-03-06T19:11:52.427

@Kaz, searching Google for "at random intervals" leads to a bunch of results where people seemingly meant from an exponential-like distribution rather than a uniform one. AFAICT, uniform distributions are only the "natural" choice in combinatorial settings. – Yonatan N – 2014-03-06T21:51:31.130

@YonatanN I believe that exponential "random intervals" can be obtained by randomly inserting (using a flat distribution) events into a block of time. It's linked to uniformity. – Kaz – 2014-03-06T23:00:57.853

The number of samples before a uniform distribution hits a certain value. The degenerate distribution, on the other hand, is the number of samples before it hits any value. Clearly, they are like the same thing. – Yonatan N – 2014-03-07T03:33:00.330

@TimSeguine I have yet to post a challenge because I give genuine concern to posting one of quality. I have two in the sandbox and more in the works. If you suggest that is a bad thing, then you are being counterproductive to your own stated wish for higher quality questions. :) Meanwhile, the counterpoint to "good questions don't attract troll answers" is "troll answers do nothing to encourage good questions" – Jonathan Van Matre – 2014-03-07T03:33:41.293

@JonathanVanMatre yeah, I was just messing with you. :) – Tim Seguine – 2014-03-07T09:58:18.730

@TimSeguine All good. :) – Jonathan Van Matre – 2014-03-07T13:18:55.383

1+1 This is a perfectly valid answer. I was about to post a 2 byte answer along the same vein, but your 0 byte one is even better. Again, the OP should have required a specific distribution if he wanted one. – Tobia – 2014-03-07T18:53:44.467

3

Java - 59 bytes

int n=255;while(n--*Math.random()>0)System.out.print(":)");

Note that you asked for "shortest code", not shortest complete program. On each run of the loop, there is a 1/7036874417766 probability that the loop exits (see How many double numbers are there between 0.0 and 1.0?). To make this a more even distribution, simply do

int n=0;n+=Math.random()*256;while(n-->0)System.out.println(":)");

Sample run: http://ideone.com/ZLppjR

Output #1:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output #2:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output #3:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

yes the outputs are identical. I'm not going to run the program until I get an output that is not identical; it would take too long.


Complete program (104 chars):

class c{public static void main(String[]a){int n=255;while(n--*Math.random()>0)System.out.print(":)");}}

Original method (92 chars):

String s="";for(int i=255;Math.random()*i-->0;)s+="x";System.out.print(s.replace("x",":)"));

Justin

Posted 2014-03-06T02:39:29.907

Reputation: 19 757

3

Ruby (25 Chars)

rand(256).times{$><<":)"}

Wanted to try my hands at ruby. What better way than a codegolf ;)

Clyde Lobo

Posted 2014-03-06T02:39:29.907

Reputation: 1 395

“Random times but ranged between 0-255” – manatwork – 2014-03-06T09:00:05.507

But you forgot to update the character count too. :) It's 28 here, you seem to counted the final newline too, which is unnecessary. And take a look at Tips for golfing in Ruby, especially to sepp2k's answer's point 3.

– manatwork – 2014-03-06T09:16:33.350

Why not just $><<":)"*rand(256)? – Doorknob – 2014-03-06T23:50:36.723

3

JavaScript, 44 bytes

alert(Array(0|Math.random()*257).join(':)'))

Note: zero-length string twice as common as other lengths (2-510).

Edit: 5 fewer characters using Date.now()%257 instead:

alert(Array(Date.now()%257).join(':)'))

Neil

Posted 2014-03-06T02:39:29.907

Reputation: 95 035

@Sting ES6 didn't exist in 2014, did it? – Neil – 2016-05-28T14:35:01.640

use new Date and you win 2 chars – Fabricio – 2014-05-12T21:42:32.870

3

q - 17 bytes

(2*1?255)[0]#":)"

or a second way:

(2*rand 255)#":)"

Chris Charles

Posted 2014-03-06T02:39:29.907

Reputation: 131

3

JavaScript (pre-ES6) 45

This is how we do it without using implementationally experimental repeat commands...

console.log(Array(Date.now()%257).join(":)"))

Output 1:
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 2:
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 3:
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

One thing I have found that both a random throw of 0 or 1 will yield no characters, so the 0-255 smileys will still hold!

WallyWest

Posted 2014-03-06T02:39:29.907

Reputation: 6 949

1repeat is not experimental. It was validated by ES6 committee. Only its implementation is experimental. – Florent – 2014-03-06T11:36:35.390

Okay, implementationally experimental.. Updated accordingly... But nevertheless, I did it without repeat... – WallyWest – 2014-03-06T11:44:26.867

1This never outputs 255 smileys. – Neil – 2014-03-07T00:28:53.060

1@WallyWest: You need one more elements than repeats for Array.join trick. If you type [1, 2, 3].join("-") you will get "1-2-3". Note two instances of dash, not three. – Konrad Borowski – 2014-03-07T16:37:49.970

Ah yes, good point... A quick change of one character should fix this... Voila! – WallyWest – 2014-03-09T05:53:56.800

3

R 37

To mirror @Sven Hohenstein's more correct solution, added cat(<>,sep=""):

cat(rep(':)',sum(sample(0:1,255,T))),sep="")

Including @Plannapus' suggestion (I'm an R user, not an R expert!):

cat(rep(':)',sample(0:255,1)),sep="")

Tested on R-Fiddle.

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Gaffi

Posted 2014-03-06T02:39:29.907

Reputation: 3 411

why not sample(0:255,1) instead of sum(sample(0:1,255,T)))? – plannapus – 2014-03-06T13:05:46.670

@plannapus Good point! Correcting. – Gaffi – 2014-03-06T13:10:20.020

3

Julia, 23

print(":)"^rand(0:255))

Usage:

julia> print(":)"^rand(0:255))
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

julia> print(":)"^rand(0:255))
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

julia> print(":)"^rand(0:255))
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

plannapus

Posted 2014-03-06T02:39:29.907

Reputation: 8 610

3

Haskell (50)

fmap(\a->concat$replicate a":)")$randomRIO(0,255)
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"

fmap(\a->concat$replicate a":)")$randomRIO(0,255)
":):):):):):):):):):):):):):):):):):):):):):):):):):):):)"

fmap(\a->concat$replicate a":)")$randomRIO(0,255)
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"

linse

Posted 2014-03-06T02:39:29.907

Reputation: 171

That's an expression, not a program. – Rhymoid – 2014-03-08T23:15:27.733

Your line is actually 49 characters, not 50. And I can shave it down to 44 for you: concat.flip replicate":)"<$>randomRIO(0,255) =D – KChaloux – 2014-03-10T12:57:58.550

KChaloux, that's awesome! I understand the concat.flip but I did not know <$>, thanks! And Rhymoid, you are right, to make it into a compilable program we'd have to add main= to it's beginning, which costs an extra 5. – linse – 2014-03-10T21:59:23.043

3

Perl 6 (20 18 bytes (I'm going to ignore scoring system, it's silly))

say ":)"x 256.rand

256.rand gives random number that is equal or higher than 0 or lower than 256. x multiplies the string given number of times, and floors the integer.

Sample:

glitchmr@feather ~> perl6 -e 'say ":)"x 256.rand'
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
glitchmr@feather ~> perl6 -e 'say ":)"x 256.rand'
:):):):):):):):):):):):)

Konrad Borowski

Posted 2014-03-06T02:39:29.907

Reputation: 11 185

I kind of like say ':)' x (^256).pick better, but there is no way to make it shorter than using rand. Although it does come in handy if you want to output all of the possible outputs in random order .say for ":)" Xx (^256).pick(*) – Brad Gilbert b2gills – 2014-11-27T15:15:45.927

2

PHP - 32

<?=str_pad('',rand(0,255),':)');

Or if we do not need to include php open tag, then it is 30:

=str_pad('',rand(0,255),':)');

Whichever suits you best

dkasipovic

Posted 2014-03-06T02:39:29.907

Reputation: 229

The equals sign is part of the php open tag in this case. You also can't leave it off in this case, otherwise the program won't print anything. – Tim Seguine – 2014-03-06T14:46:50.970

It will not print anything either way, with or without equals sign. Well, to be more precise it will print the source code if you omit the php tag. What is the difference between a line beginning with echo (space in front) and a line beginning with = (no space in front). If you add php opening tag <? before any of them, they will both work? – dkasipovic – 2014-03-06T14:54:44.477

1The difference: a line beginning with = is not valid syntax. <?echo 1; is valid syntax, btw(there need not be a space before echo). You see the point I am making but want to language lawyer anyway. – Tim Seguine – 2014-03-06T15:01:14.067

Yeah, you are right about that, but I was just pointing out, as far as execution goes, neither of them works without <? if you put them in php interpreter. But I see your point, that's what I thought too, that's why I wrote 32 as length. – dkasipovic – 2014-03-06T17:16:44.040

2

C: 44 (39 if sloppy)

Extracting randomness from the pointer provided. Granted, it is aligned (multiples of 8) but it's a start:

main(a,b){while(b--&255)printf(":)");}

Fixed at expense of 5 chars:

main(a,b){b/=8;while(b--&255)printf(":)");}

Edit: noticed that newlines are not allowed. A solution is to replace puts with printf adding two chars. I now noticed that Abhijit's solution has the same idea. Sorry.

orion

Posted 2014-03-06T02:39:29.907

Reputation: 3 095

2

Java - 84

System.out.println(new String(new char[(int)(Math.random()*255)]).replace("\0",":)"));

Fairly long, but interesting.

Rudi Kershaw

Posted 2014-03-06T02:39:29.907

Reputation: 121

2

Excel Speadsheet Formula (also works in Google docs) - 21

=REPT(":)",RAND()*250)

Output 1:
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output 2:
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output 3:
:):):):):):):):):):):):):):):):):):)

John

Posted 2014-03-06T02:39:29.907

Reputation: 121

2

Brainfuck (shell support) - 49/62

This bf program (49 bytes) reads a byte from stdin (0-255) and prints that many smileys:

+[--------->+<]>+<++[------>>+<<]>>--<<,[->.>.<<]

Compile this to a file a and execute

./a</dev/random

Alternatively, assuming your PATH is set up properly (13 bytes):

a</dev/random

62 bytes in total, guaranteed randomness.

1st output

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

2nd output

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

3rd output

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Tobias

Posted 2014-03-06T02:39:29.907

Reputation: 121

2

Python 3, 38 bytes.

from random import*
':)'*randrange(256)

OUTPUTS

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Alex Thornton

Posted 2014-03-06T02:39:29.907

Reputation: 131

You could use print(':)'*__import__('random').randrange(256)). – Toothbrush – 2014-03-08T20:42:32.717

2

x86 DOS Assembly - 27 25

Not the greatest attempt in the world (complete with crappy LCG PRNG), but I had to do something. This is a COM file. The raw source is (in hex):

B42CCD210FAFCA32EDBA1601B409E304CD21E2FCCD203A2924

In more readable ASM:

    ; Get system time (for random amount)
    mov ah, 02Ch
    int 021h

    ; Make cl pseudo-random
    imul cx, dx
    xor ch, ch

    ; Prepare for our print
    mov dx, Smile
    mov ah, 9

    ; Loop a random number of times
    jcxz Done
MainLoop:
    int 021h
    loop MainLoop
Done:

    ; End
    int 020h

    ; Our smile
Smile:
    db ':)$'

Sample output:

C:\TEMP>smiley1
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
C:\TEMP>smiley1
:):):):):):)
C:\TEMP>smiley1
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):)

EDIT Changed to int 020h per DocMax

Mark Ormston

Posted 2014-03-06T02:39:29.907

Reputation: 799

This is [tag:code-golf]. You are supposed to remove comments and unnecessary whitespace, and use 1-character variable names. – None – 2014-03-08T22:09:44.847

The resulting code is binary hex values. I can remove the spacing from that. I added the readable translated version so people can see what it is. – Mark Ormston – 2014-03-08T22:10:18.417

OK, that is good practice too. – None – 2014-03-08T22:10:56.650

It may not be as universally supported, but if you limit the versions of DOS that your answer runs on you can use int 20 instead of xor ah,ah/int 21 to save 2 more bytes. – DocMax – 2014-03-08T23:01:03.520

@DocMax - Thanks! I never really relied on int 020h much, but it certainly does work. Updating my answer. – Mark Ormston – 2014-03-08T23:08:43.633

2

JavaScript

Can't you just do something like this?

var s = ""; for(var a = 0; a<Math.random()*255;a++){s+=":)";} alert(s);

potato

Posted 2014-03-06T02:39:29.907

Reputation: 111

2

Pyth, 8 (non-competing)

Note: This answer is non-competing since Pyth was invented after the challenge was posted.

*O256":)

I'm surprised Pyth hasn't been used yet.

Output

Output 1
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 2
:):)
Output 3
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Explanation:

*             Multiply...
 O256         Random from range(255)
     ":)      ...By ":)". End quote is inferred.
              (Printing is implicit)

Moose

Posted 2014-03-06T02:39:29.907

Reputation: 883

Probably because Pyth appeared after the question was posted. – manatwork – 2015-10-15T19:04:25.407

1

Javascript (on nodejs repl) - 47 chars

Array(Math.floor(Math.random()*255)).join(':)')

output #1

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

output #2

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

output #3

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Mark Dee

Posted 2014-03-06T02:39:29.907

Reputation: 119

You can save char by doing ~~(Math.random()*255) instead of Math.floor(Math.random()*255). Also get rid of your spaces. – Danny – 2014-03-06T14:57:25.360

I didn't actually know how that works but it does. Someone also suggested (0|Math.random()*255) which produces the same result. I think it's time for me to study bitwise, I usually skip those chapters on most books I've read. – Mark Dee – 2014-03-07T02:29:31.590

Good answers on SO about both. ~~ and bitwise or 0

– Danny – 2014-03-08T01:57:39.573

1

C: 62

(61 characters plus newline)

main(){int x=time((int*)0)&510;while(x--)putchar(x&1?58:41);}
  • Avoids the undefined behavior of calling variadic functions without a prototype in scope.
  • Slight abuse in passing a null pointer possibly of the wrong type to time; however, pointers are all represented the same way on many platforms: the function call time((long*)0) won't generate code that is any different from time((int*)0).
  • ASCII dependency in putchar call: the IBM mainframe salesman was out playing golf.
  • Not very random, but at least the output changes. Seeding a PRNG adds length.

This version elicits a "data definition has no type or storage class" diagnostic from GCC:

x;main(){x=time((int*)0)&510;while(x--)putchar(x&1?58:41);}

According to ISO C syntax, a declaration must have specifiers, and according to the Constraints, it "shall declare at least a declarator (other than the parameters of a function or the members of a structure or union), a tag, or the members of an enumeration." (ISO 9899:1999 6.7)

Kaz

Posted 2014-03-06T02:39:29.907

Reputation: 372

This is wasteful. Remove braces around putchar. Remove (int*) from time (I don't even do that in real code, let alone golfing). You may also remove int, depending on the standard. – orion – 2014-03-06T16:43:22.380

@orion Good call. The braces were left over from a version where I had two putchars. Those have been combined with the comma operator. – Kaz – 2014-03-06T19:07:14.707

@orion The (int *) stays; without it, we are passing an int to time. – Kaz – 2014-03-06T19:09:53.203

It's fine, pointers are integers and zero is just zero, when compiled, there's no distinction between pointers and int/long types. Zero means to ignore it anyway. There are puritans that swear by having exact types but that's not even strictly required in c++, let alone c. Try it. – orion – 2014-03-06T21:43:52.127

@orion Yes, there is a distinction between integers and pointers. For example, on my 64 bit Debian box, an int is 4 bytes wide, and a pointer is 8 bytes wide. That's just one kind of difference. On some machines, integers and pointers may be passed or returned in different registers even if they are the same size. E.g. Motorola 68000: pointers in regs A0-A7, data values in D0-D7. – Kaz – 2014-03-07T04:40:55.507

Sure, I said int/long/[technically long long], depending on the system, but it's still implicitly convertible. 4-byte 0 is cast implicitly to 8-byte 0, it still means null pointer, which is ignored by time(0). Just do it and compile. It works perfectly, no warnings or errors. – orion – 2014-03-07T08:22:55.200

@orion Of course there are no warnings; there is no prototype for time; the <time.h> header has not been included! Since there is no prototype declaration, no conversion (what you're calling "implicit cast") of arguments to the parameter type takes place. If you call time(3.0), then a double is passed, not 3. You could pass a structure: struct foo { char a[23]; } x; time(x);. – Kaz – 2014-03-07T09:59:00.260

Wow, you are using (int*) (insane portability for something that would work anyway on common platforms), and yet you assume ASCII. If you seriously are going to be lolportable, perhaps consider replacing ASCII charcodes with real characters. And not specifying x as function argument (I know, undefined behavior - main takes 0 or 2 arguments, not 1), even if it works on most platforms. – Konrad Borowski – 2014-03-07T16:43:41.040

@xfix Your reasoning is flawed. ASCII is much more ubiquitous than ABI-level interchangeability of int and pointers, which have a different size on a whole lot of mass-produced, consumer-grade hardware! Worrying about non-ASCII systems is what is "lolportable". – Kaz – 2014-03-07T19:33:36.160

@xfix The program is hardly obsessed with portability. It depends on the interchangeability of pointers of different types (that int * substitutes for time_t *). It also depends on time_t being an integer (ISO C says "arithmetic type capable of representing time"). I made some practical assumptions which hold quite broadly to keep the program short, without drifting into idiot land. – Kaz – 2014-03-07T19:41:25.170

1

Coreutils and Bash 36

yes :\)|head -$[RANDOM>>7]|tr -d \\n

I borrowed the creative use of RANDOM from @DigitalTrauma.

Testing:

$ yes :\)|head -$[RANDOM>>7]|tr -d \\n

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

$ yes :\)|head -$[RANDOM>>7]|tr -d \\n

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

$ yes :\)|head -$[RANDOM>>7]|tr -d \\n

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Thor

Posted 2014-03-06T02:39:29.907

Reputation: 2 526

1

JAVA 61

for(int i=0;i<Math.random()*255;i++){System.out.print(":)");}

Output:

:):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):)

NULL

Posted 2014-03-06T02:39:29.907

Reputation: 19

1

Quite bad randomization. http://pastebin.com/va2sgBur . Anyway, I'm afraid that will not compile in Java.

– manatwork – 2014-03-06T11:24:46.130

It will compile as tested it :) – NULL – 2014-03-06T12:26:59.170

Not here: http://pastebin.com/92MqU7zy

– manatwork – 2014-03-06T12:54:38.650

I guess default package is not getting loaded for u – NULL – 2014-03-06T13:23:11.777

What manatwork means (I suppose) is that you should add something like class C{public static void main(String[]a){...}} to your code for it to be compilable. – Paŭlo Ebermann – 2014-03-06T22:27:05.490

@Paŭlo What is the standard way of code-golfing Java: to include or not to include? – Ypnypn – 2014-03-07T03:32:19.803

thn i have wrtie class, package etc also? – NULL – 2014-03-07T10:56:44.000

@Ypnypn The standard is to include, unless the challenge asks for a function, in which case, just declare a method – Justin – 2014-05-19T21:15:35.023

1

Python - 40

import random;':)'*random.randint(0,255)

output:

>>> import random;':)'*random.randint(0,255)
':):):)'

>>> import random;':)'*random.randint(0,255)
':):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)'

>>> import random;':)'*random.randint(0,255)
':):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)'

Brian

Posted 2014-03-06T02:39:29.907

Reputation: 21

1

PHP - 28

=str_pad('',rand()&255,':)')

or

=str_repeat(':)',rand()&255)

These are 30 if you include <?

Liam

Posted 2014-03-06T02:39:29.907

Reputation: 111

PHP programs have to end with ; (unless you have {} block, or something like this), and = is not a token by itself (-r that allows you not to specify <? considers program that begins with = to be a syntax error). Change your program to have <? at beginning, and ; at end. – Konrad Borowski – 2014-03-07T16:40:16.853

1

Windows Powershell - 30 21

Thanks to manatwork for telling me I don't need "-maximum" to specify upper limit

":)"*(get-random 255)
:):):):):):):):):):):):):):):):):)

":)"*(get-random 255)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

":)"*(get-random 255)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Brian

Posted 2014-03-06T02:39:29.907

Reputation: 1 209

The Get verb is implied. you can write random 255 instead get-random 255 – mazzy – 2018-12-11T13:14:46.070

You can omit -Maximum. At least in PowerShell 2.0. – manatwork – 2014-03-06T15:27:16.657

For 0-255, you need 256 in the Get-Random call. (Like in my own answer). – DocMax – 2014-03-08T22:59:20.327

1

Python 116

a=list(string.printable*255)
random.shuffle(a)
print ''.join([ x+y for x,y in zip(*[iter(a)]*2) if x==":" and y==")"])

Relying on that popularity aspect to bring score down...

VBCPP

Posted 2014-03-06T02:39:29.907

Reputation: 451

1

Lua, 36

print((':)'):rep(math.random(255)))

Sample output:

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Rastus Vernon

Posted 2014-03-06T02:39:29.907

Reputation: 11

1

Bash, 14-45 bytes

(the last time I tried to post this, the question had been suddenly closed)

This fork bomb is sad because it can never explode.

:(){ :|\)& };:

bash: ): command not found
bash: ): command not found
bash: ): command not found

If you execute this, you will probably want to pkill -1 bash, since each process survives for only moments.

To make it stop automatically, it can be changed to:

r=$[RANDOM>>7];:(){ [ $[r--] = 0 ]||:|\)& };:

user130144

Posted 2014-03-06T02:39:29.907

Reputation: 303

1

Python - 42 chars

import random;random.randrange(0,256)*':)'

could have been reduced to 28 chars if import wasn't counted.

output:

:):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Mark Dee

Posted 2014-03-06T02:39:29.907

Reputation: 119

Shave off 1 char with from ... import*: from random import*;randrange(0,256)*':)' – Justin – 2014-05-19T21:14:18.520

1

Scala repl short 29

":)"*util.Random.nextInt(256)

First output:

res9: String = :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):): 
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):)

Second output

res10: String = :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
 :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
 ):):):):):):):):):):):):):):):):):):)

Third output

res11: String = 
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):
):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
:):):):):):):):):):):):):):):):):):):):):):):):)

I love scala =)

Benjamin Scherer

Posted 2014-03-06T02:39:29.907

Reputation: 111

1

PHP 28

str_repeat(':)',rand(0,255))

Output 1

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output 2

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Output 3

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

Jonnny

Posted 2014-03-06T02:39:29.907

Reputation: 111

1

Clojure

  (doseq [t (take (rand-int 256) (repeat ":)"))]
    (print t))

Mamun

Posted 2014-03-06T02:39:29.907

Reputation: 181

1

import random
x=random.randint(0,255)
print(':)'*x)

Pruthvi Raj

Posted 2014-03-06T02:39:29.907

Reputation: 141

ah i didnt notice that someone already did the same program!! – Pruthvi Raj – 2014-03-09T07:49:50.230

You have to write :) between 0 and 255 times. This program cannot print :) 42 times, for example. Also, it could be shortened, by removing whitespace around = operator. If you use Python 2, you can remove parenthesis around print. You should also specify your language. – Konrad Borowski – 2014-03-09T08:22:50.237

1

C# - 162

using System;using System.Linq;namespace G{class Program{static void Main(){Console.WriteLine(string.Join("",Enumerable.Repeat(":)",new Random().Next(255))));}}}

Pretty Print:

using System;
using System.Linq;

namespace G
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine(string.Join("",Enumerable.Repeat(":)", new Random().Next(255))));
        }
    }
}

Output:

1

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):) Press any key to continue . . .

2

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):) Press any key to continue . . .

3

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) :):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):) Press any key to continue . . .

Matthew Steeples

Posted 2014-03-06T02:39:29.907

Reputation: 131

Without going into heavy golfing, a shorter version - 118 - using System;class P{static void Main(){Console.WriteLine(new string('.',new Random().Next(256)).Replace(".",":)"));}}. Yours can be shortened down to 142 by removing the namespace and renaming Program to P. – JimmiTh – 2014-05-12T19:54:39.157

Wow, thanks for that. Didn't realise that namespaces were optional – Matthew Steeples – 2014-05-13T11:10:35.780

1

C++ - 76 72

(counting the newline as one character)

#include <iostream>
main(){for(int k;++k<(((long)&k)%255);)std::cout<<":)";}

Actually, using a while and some C-style output I managed to shave off a few more:

#include <cstdio>
main(){int k;while(++k<(((long)&k)%255))printf(":)");}

Output examples:

:):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

CompuChip

Posted 2014-03-06T02:39:29.907

Reputation: 439

1

Python 3.x 47

import random;print(':)'*random.randint(0,255))

as Doorknob said, boring.

Caridorc

Posted 2014-03-06T02:39:29.907

Reputation: 2 254

Since this is code-golf you should include a byte count in your title. – user12205 – 2014-05-12T22:50:46.983

1

BASH 34 characters

yes ":)" | head -$(($RANDOM%255))

I had to use a head in my code ;)

CousinCocaine

Posted 2014-03-06T02:39:29.907

Reputation: 1 572

1

Simplex v.0.5, 17 bytes

(":)")257{ppj1X}g
(    )257            ~~ repeat inner expression 257 times
 ":)"                ~~ set the current bytes to :, the next byte to ), and increment pointer by two
         {     }     ~~ repeat inner expression until current byte is zero
          pp         ~~ remove two cells, moving pointer backwards twice
            j        ~~ insert a new cell
             1       ~~ the cell is zero, and thus is initialized to 1
              X      ~~ sets the cell to an integer N, 0 <= N <= 1
                g    ~~ clears the strip and outputs characters as ASCII characters.

Technically, this compiles to the following Simplex code:

":)"":)"...(257 times total)...":)"{ppj1X}g

Now, this abuses the fact that the exit chance need not to be equally distributed. Here are some example outputs using my interpreter on my hard drive (working on releasing it sometime on the GitHub):

Output 1
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 2
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)
Output 3
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)

FYI, the chance of getting one :) is:

So, yeah, it's still possible, yet unlikely.

Conor O'Brien

Posted 2014-03-06T02:39:29.907

Reputation: 36 228

0

Python, 16 characters

print ":)"*id(1)

Warning!!!! "Random" on my system is typically between 100-10 million or so this can take a while:

$ python dumb.py | wc -c
75397329
$ python dumb.py | wc -c
43243729

Add four bytes and mod it by 256. Woo.

meawoppl

Posted 2014-03-06T02:39:29.907

Reputation: 261

Remove the number 16 from your heading and show that code differently – Mukul Kumar – 2014-03-09T12:51:40.440

0

Extended BrainFuck: 13

,(->|":)"(-))

This is bending the rules a little since BrainFuck (runtime of EBF) doesn't have a random function so it has to get random bytes as input.

Compilation:

sylwester@pussycat ~> bf ebf.bf < ransmiley.ebf > ransmiley.bf

3 runs:

sylwester@pussycat ~> bf ransmiley.bf </dev/random
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)⏎
sylwester@pussycat ~> bf ransmiley.bf </dev/random
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)⏎
sylwester@pussycat ~> bf ransmiley.bf </dev/random
:):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)⏎
sylwester@pussycat ~> 

The examples here are shown with bf which is a BrainFuck interpreter implementation available in all debian based linux distros with:

sudo apt-get install bf

Also it can be compiled from source

BrainFuck: 51

,[->>+++++++[-<++++++++>]<++.>++++[-<---->]<-.[-]<]

This is just the compiled EBF code. It seems pretty compact.

Sylwester

Posted 2014-03-06T02:39:29.907

Reputation: 3 678

0

SQL, 79

Because, why not

declare @c int;set @c=rand()*255;while(@c<255) begin print ':)';set @c=@c+1;end

iamkrillin

Posted 2014-03-06T02:39:29.907

Reputation: 280

0

Javascript: 24 23 (-1 if you not count 's')

This code needs as input 255 ":)" characters in s.

s.substr(new Date%257*2)

Second approach:

s.slice(new Date%257*2)

Outputs

input: ":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)".substr(new Date%256*2)
output: ":):):):):):):):):):):):):):):):):):):):):):):):):)"
input: same
output: ":):):):):)"
input: same
output: ":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"

Fabricio

Posted 2014-03-06T02:39:29.907

Reputation: 1 605

0

Cobra - 60

class P
    def main
        for i in Random().next(256),print ":)"

Batch - 60

@set /aa=%random%%%256
@for /l %%i in (0,1,%a%) do @echo :)

Οurous

Posted 2014-03-06T02:39:29.907

Reputation: 7 916

0

Ruby - 15 bytes

This was a fun, simple little code golf. Here's the code:

p":)"*rand(255)

which prints something like

":):):):):):):):):):):):):):):):):):):):)"

To print without the quotes you would have to add 3 bytes and say:

puts":)"*rand(255)

Aearnus

Posted 2014-03-06T02:39:29.907

Reputation: 251

0

AppleScript, 52 bytes

So, uh, yeah.

repeat random number from 0 to 255 times
log":)"
end

I think this is fairly self explanatory.

Addison Crump

Posted 2014-03-06T02:39:29.907

Reputation: 10 763

0

CJam, 12 11 10 chars

Y8#mr":)"*

I'm very new to golfing (this is my first post), so I'm not quite sure what to say here. :-P

Jamie Sanborn

Posted 2014-03-06T02:39:29.907

Reputation: 121

0

Hassium, 47 Bytes

func main()print(":)"*new Random().next(0,255))

Run and see expanded online here

Jacob Misirian

Posted 2014-03-06T02:39:29.907

Reputation: 737

0

Microscript II, 10 bytes

":)"s256R*

SuperJedi224

Posted 2014-03-06T02:39:29.907

Reputation: 11 342

0

Hoon, 34 bytes

(runt (~(rad og eny) 256)^':)' "")

++runt prepends b a times. Giving it just an empty tape, pulling a random number from ++rad:og with the entropy variable eny.

Really, the only interesting thing in this is the syntax a^b - it's sugar for [a b] which saves two bytes, since runt really needs to be called like (runt [a b] c)

> (runt (~(rad og eny) 256)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"
> (runt (~(rad og eny) 256)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"
> (runt (~(rad og eny) 256)^':)' "")
":):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):):)"

RenderSettings

Posted 2014-03-06T02:39:29.907

Reputation: 620