Generate a 6 character string from a 15 character alphabet

CJam (23 + 14 + 10 = 47 bytes)

Arbitrary alphabet: 23 bytes (online demo)

{"ABC123!@TPOI098"mR}6*

Hexadecimal alphabet: 14 bytes (online demo)

{FmrAbHb'0+}6*

Custom alphabet: ABCDEFGHIJKLMNO, 10 bytes (online demo)

{Fmr'A+}6*

Dissection

The hexadecimal one is the interesting one:

{      e# Loop...
  Fmr  e#   Select a random number from 0 to 14
  AbHb e#   Convert to base 10 and then to base 17
       e#   (i.e. add 7 if the number is greater than 9)
  '0+  e#   Add character '0' (i.e. add 48 and convert from integer to character)
       e#   Note that 'A' - '0' = 17
}6*    e# ...six times

The six characters are left on the stack and printed automatically.


Jelly, 38 bytes

TryItOnline links A, B, and C.

A: ABC123!@£POI098, 22 bytes

“ABC123!@£POI098”Wẋ6X€

(thinking about a compression to lessen this one)

B: 0123456789ABCDE, 8 bytes:

ØHṖWẋ6X€

C:123456789ABCDEF (choice), 8 bytes:

ØHḊWẋ6X€

How?

...Wẋ6X€ - common theme
   W     - wrap (string) in a list
    ẋ6   - repeat six times
      X€ - random choice from €ach

ØH...... - hexadecimal digit yield: "0123456789ABCDEF"

..Ṗ..... - pop: z[:-1] (B)

..Ḋ..... - dequeue: z[1:] (C)

Perl, 46 + 26 + 26 = 98 bytes

A lot of the credit goes to @Dom Hastings for saving 13 bytes!

The 3 programs are pretty much identical, except for the alphabet that changes.

  • Hardcoded alphabet (ABC123!@)POI098 in this example) -> 46 bytes:

    say map{substr"ABC123!@)POI098",15*rand,1}1..6

  • Fixed alphabet 0123456789ABCDE -> 26 bytes:

    printf"%X",rand 15for 1..6

  • Custom alphabet 0123456789ABCDE in that case -> 26 bytes:

    printf"%X",rand 15for 1..6

You can put them all in a file to run them :

$ cat 6chr_strings.pl
say map{substr"ABC123!@)POI098",15*rand,1}1..6;
say "";
printf"%X",rand 15for 1..6;
say "";
printf"%X",rand 15for 1..6;
say "";
$ perl -M5.010 6chr_string.pl
CB8!8!
24D582
9ED58C

(the say ""; are just here to improve the output format)