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:


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:

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

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

list of results from the other random number generators


  • 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?
  • 1
    $\begingroup$ I observe the same thing with MMA version 13.0.1 $\endgroup$ Jun 22 at 18:54
  • $\begingroup$ "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. $\endgroup$ Jun 22 at 19:20
  • 1
    $\begingroup$ The kernel crashes even in version 8.0.4, this seems to be an old bug. $\endgroup$
    – innaiz
    Jun 23 at 8:41
  • 5
    $\begingroup$ Reporting this as a bug. $\endgroup$ Jun 23 at 14:45
  • $\begingroup$ @DanielLichtblau Thank you! If your report generates a tracking token that you can share, would you mind adding it to the question? $\endgroup$
    – MarcoB
    Jun 23 at 15:21


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.