Skip to main content
deleted 117 characters in body
Source Link
Business Cat
  • 9.2k
  • 1
  • 17
  • 37

CJam, 21 1717 12 bytes

Edit: Had to change '[ to '\ since Z wasn't included.Thanks to Martin Ender for saving me 5 bytes!

New version

'\,{,'A:,s_el-}%M*mr0=mR

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!Try it online!

Explanation

'\,               e# Push the range containingof all characters up to '[' (next ASCII character after Z)'Z'
   {,'A:,-}%        e# For each characterone, pushtake the range of all characters from itup to 'A'. it
           s       e# This will be anConvert emptythe stringarray forof anyranges characterto beforeone 'A'.string
       _el-   e# M*Subtract the lower case version e#of Jointhe withstring nofrom separatoritself
             mr   e# ShuffleThis theleaves string
only capital letters in the string
          0=mR e# GetTake thea firstrandom character from it

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character

CJam, 21 17 bytes

Edit: Had to change '[ to '\ since Z wasn't included.

New version

'\,{,'A,-}%M*mr0=

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!

Explanation

'\,               e# Push the range containing all characters up to '[' (next ASCII character after Z)
   {,'A,-}%       e# For each character, push the range of all characters from it to 'A'. 
                  e# This will be an empty string for any character before 'A'.
           M*     e# Join with no separator
             mr   e# Shuffle the string
               0= e# Get the first character

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character

CJam, 21 17 12 bytes

Thanks to Martin Ender for saving me 5 bytes!

New version

'\,:,s_el-mR

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!

Explanation

'\,          e# Push the range of all characters up to 'Z'
   :,        e# For each one, take the range of all characters up to it
     s       e# Convert the array of ranges to one string
      _el-   e# Subtract the lower case version of the string from itself
             e# This leaves only capital letters in the string
          mR e# Take a random character from it

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character
added 134 characters in body
Source Link
Business Cat
  • 9.2k
  • 1
  • 17
  • 37

CJam, 21 17 bytes

Edit: Had to change '[ to '\ since Z wasn't included.

New version

'['\,{,'A,-}%M*mr0=

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!Try it online!

Explanation

'['\,               e# Push the range containing all characters up to 'Z''[' (next ASCII character after Z)
   {,'A,-}%       e# For each character, push the range of all characters from it to 'A'. 
                  e# This will be an empty string for any character before 'A'.
           M*     e# Join with no separator
             mr   e# Shuffle the string
               0= e# Get the first character

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character

CJam, 21 17 bytes

New version

'[,{,'A,-}%M*mr0=

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!

Explanation

'[,               e# Push the range containing all characters up to 'Z'
   {,'A,-}%       e# For each character, push the range of all characters from it to 'A'. 
                  e# This will be an empty string for any character before 'A'.
           M*     e# Join with no separator
             mr   e# Shuffle the string
               0= e# Get the first character

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character

CJam, 21 17 bytes

Edit: Had to change '[ to '\ since Z wasn't included.

New version

'\,{,'A,-}%M*mr0=

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!

Explanation

'\,               e# Push the range containing all characters up to '[' (next ASCII character after Z)
   {,'A,-}%       e# For each character, push the range of all characters from it to 'A'. 
                  e# This will be an empty string for any character before 'A'.
           M*     e# Join with no separator
             mr   e# Shuffle the string
               0= e# Get the first character

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character
New version; added 91 characters in body; deleted 1 character in body; added 118 characters in body
Source Link
Business Cat
  • 9.2k
  • 1
  • 17
  • 37

CJam, 2121 17 bytes

New version

'[,{,'A,-}%M*mr0=

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!

Explanation

'[,               e# Push the range containing all characters up to 'Z'
   {,'A,-}%       e# For each character, push the range of all characters from it to 'A'. 
                  e# This will be an empty string for any character before 'A'.
           M*     e# Join with no separator
             mr   e# Shuffle the string
               0= e# Get the first character

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

[Try it online!][1]

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character

[1]: http://cjam.aditsu.net/#code=26%2C%3A)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e%23%20Push%201%2C%202%2C%20...%2026%0A%20%20%20%20%20'%5B%2C'A%2C-%20%20%20%20%20%20%20%20%20%20e%23%20Push%20'A'%2C%20'B'%2C%20...%20'Z'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20.%20%20%20%20%20%20%20e%23%20Vectorize%3A%20repeat%20each%20letter%20the%20corresponding%20number%20of%20times%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M%20%20%20%20%20e%23%20Join%20with%20no%20separator%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mr%20%20%20e%23%20Shuffle%20the%20string%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200%3D%20e%23%20Get%20the%20first%20character

CJam, 21 bytes

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

[Try it online!][1]

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character

[1]: http://cjam.aditsu.net/#code=26%2C%3A)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20e%23%20Push%201%2C%202%2C%20...%2026%0A%20%20%20%20%20'%5B%2C'A%2C-%20%20%20%20%20%20%20%20%20%20e%23%20Push%20'A'%2C%20'B'%2C%20...%20'Z'%0A%20%20%20%20%20%20%20%20%20%20%20%20%20.%20%20%20%20%20%20%20e%23%20Vectorize%3A%20repeat%20each%20letter%20the%20corresponding%20number%20of%20times%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20M%20%20%20%20%20e%23%20Join%20with%20no%20separator%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mr%20%20%20e%23%20Shuffle%20the%20string%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%200%3D%20e%23%20Get%20the%20first%20character

CJam, 21 17 bytes

New version

'[,{,'A,-}%M*mr0=

This forms an array of strings following the pattern A, AB, ABC, and so on. It flattens it and chooses a random character. Since this string contains 26 A's, 25 B's, 24 C's, and so on, each letter has a distinct probability of being chosen.

Try it online!

Explanation

'[,               e# Push the range containing all characters up to 'Z'
   {,'A,-}%       e# For each character, push the range of all characters from it to 'A'. 
                  e# This will be an empty string for any character before 'A'.
           M*     e# Join with no separator
             mr   e# Shuffle the string
               0= e# Get the first character

Old version

26,:)'[,'A,- .*M*mr0=

Gets distinct probabilities by making a string in which each letter appears a number of times equal to its position in the alphabet.

26,:)                 e# Push 1, 2, ... 26
     '[,'A,-          e# Push 'A', 'B', ... 'Z'
             .*       e# Vectorize: repeat each letter the corresponding number of times
               M*     e# Join with no separator
                 mr   e# Shuffle the string
                   0= e# Get the first character
Source Link
Business Cat
  • 9.2k
  • 1
  • 17
  • 37
Loading