3
\$\begingroup\$

This question already has an answer here:

Task:

Given two positive integers, generate a random integer between them (inclusive) and then output all its prime factors.

Examples:

Input:   Random Number:     Output:
1,2      2                  [2]
12,46    18                 [2,9]
142,17   40                 [2,2,2,5]

Scoring:

This is so the least bytes wins!

\$\endgroup\$

marked as duplicate by Comrade SparklePony, Erik the Outgolfer, Beta Decay, a spaghetto, Rɪᴋᴇʀ Jun 10 '17 at 16:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5
\$\begingroup\$

05AB1E, 4 bytes

Ÿ.RÒ

Explanation:

Ÿ       Create a list [a .. b]
 .R     Pick a random element
   Ò    Prime factors.

Try it online!

\$\endgroup\$
4
\$\begingroup\$

Jelly, 5 4 bytes

rXÆf

Try it online!

How it works

rXÆf 
r     inclusive range
 X    random element's
  Æf  prime factorization

-1 byte thanks to @LeakyNun

\$\endgroup\$
  • \$\begingroup\$ 4 bytes: rXÆf \$\endgroup\$ – Leaky Nun Jun 10 '17 at 15:42
  • \$\begingroup\$ Thanks. I thought there would be a problem with range using the first argument and the output of X applied to the second argument. \$\endgroup\$ – fireflame241 Jun 10 '17 at 15:44
  • 1
    \$\begingroup\$ The 21 rule only applies in monadic chains. \$\endgroup\$ – Leaky Nun Jun 10 '17 at 15:50
3
\$\begingroup\$

Mathematica, 38 bytes

#&@@@FactorInteger@RandomInteger@{##}&
\$\endgroup\$
2
\$\begingroup\$

Pyth, 4 bytes

PO}F

Test suite.

\$\endgroup\$
1
\$\begingroup\$

PHP, 79 bytes

for($a=rand($argv[1],$argv[$i=2]);1<$a;)$a%$i?$i++:$a/=$i+!$r[]=$i;print_r($r);

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pyffman 1, 90 80 bytes

This is a joke language that was published today (but before the challenge!). It is based on compressing Python using a pre-made Huffman code based on a corpus of golfed Python. Since the code doesn't really consist of bytes (it's bit-based, due to its huffmannness), I give you here the hexdump obtained using xxd.

00000000: 9c23 9c8f f5fe 9e1d 744a 4ac4 860f 2fcb  .#......tJJ.../.
00000010: 1218 3cbf 70d5 9577 b8cb 4059 44a4 2dbf  ..<.p..w..@YD.-.
00000020: fbaa 9763 4a75 bbbb 90e1 7ac8 410f fbba  ...cJu....z.A...
00000030: 0c91 a0d8 528d dde3 8fd9 0e19 0c56 2ca6  ....R........V,.
00000040: c699 893b 9e1b bc47 fb29 b1a6 624e 79e8  ...;...G.)..bNy.

(The original Python code this is based on is 164 158 bytes.)

\$\endgroup\$
1
\$\begingroup\$

MATL, 5 bytes

SYrYf

Try it at MATL Online

Explanation

        % Implicitly grab input as a 1 x 2 array
S       % Sort the input such that the lower end of the range comes first
Yr      % Generate a random integer in this range
Yf      % Compute it's prime factors
        % Implicitly display the result
\$\endgroup\$
1
\$\begingroup\$

CJam, 13 bytes

{$~),\,-mRmf}

Anonymous block that expects an array of two numbers in the stack and replaces it by an array with the output.

Try it online!

Explanation

{       e# Begin block
  $     e# Sort array
  ~     e# Split into the two numbers, a and b, where b is greater
  )     e# Increment b
  ,     e# Range from 0 to b
  \     e# Swap
  ,     e# Range from 0 to a-1
  -     e# Set difference: range from a to b
  mR    e# Random choice
  mf    e# Array of prime factors
}       e# End block
\$\endgroup\$
1
\$\begingroup\$

Japt, 7 6 bytes

óV ö k

Try it online!

Explanation

oVÄ ö k
oVÄ        range of integers between first input and second input + 1
    ö      get a random item from the array
      k    return all prime factors

Saved a byte thanks to ETHproductions

\$\endgroup\$
  • \$\begingroup\$ @ETHproductions You're right, thanks! \$\endgroup\$ – Tom Jun 10 '17 at 17:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.