# Kernel crash with RandomChoice

Bug introduced in 8.0.4 and persisting through 13.0.1 or later (case: 4948255)

I use Mathematica 12.3.1 for Microsoft Windows (64 bit). While playing with some code inspired by this recent question, I stumbled upon a call to RandomChoice that seems to reliably crash my kernel. Playing with different methods for the random number generator, I noticed that the "Congruential" method does not handle weighted choices well.

First, this code executes repeatedly and with no problem:

SeedRandom[20220622, Method -> "Congruential"];
RandomChoice[Range[10, 13]]
(* Out: 12 *)


The following similar call, which should in principle be equivalent but uses explicit constant weights, reliably crashed my kernel every time I ran it:

(* BEWARE - POTENTIAL KERNEL CRASH *)

SeedRandom[20220622, Method -> "Congruential"];
RandomChoice[{1, 1, 1, 1} -> Range[10, 13]]


Other values for the weights (e.g. {1, 2, 2, 1} or {1/4, 1/4, 1/4, 1/4}, or corresponding lists of machine-precision numbers) all have the same behavior, i.e. they lead to a crash.

Other generators are not affected:

ClearAll[tester]
tester[method_String] := (
SeedRandom[20220622, Method -> method];
{method, RandomChoice[{1, 1, 1, 1} -> Range[10, 13]]}
)

TableForm[
tester /@ {
"ParallelGenerator", "ParallelMersenneTwister",
"MersenneTwister", "MKL",
"Rule30CA", "Rule50025CA",
"ExtendedCA", "Legacy", "OpenSSL"}
]


## Questions:

• Is this a bug, or am I mishandling the random number framework?
• Is there a first-principle reason why the "Congruential" method cannot handle weights?
• Is this behavior version-dependent? OS-dependent?
• I observe the same thing with MMA version 13.0.1 Jun 22 at 18:54
• "Is there a first-principle reason why the "Congruential" method cannot handle weights?" - there isn't, which is all the more reason to report this crash to Support. Jun 22 at 19:20
• The kernel crashes even in version 8.0.4, this seems to be an old bug. Jun 23 at 8:41
• Reporting this as a bug. Jun 23 at 14:45
• @DanielLichtblau Thank you! If your report generates a tracking token that you can share, would you mind adding it to the question? Jun 23 at 15:21