8
$\begingroup$

Bug introduced in 8.0.4 and persisting through 13.0.1 or later (case: 4948255). It has been fixed in 13.2.0 or earlier.


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"}
]

list of results from the other random number generators

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?
$\endgroup$
9
  • 1
    $\begingroup$ I observe the same thing with MMA version 13.0.1 $\endgroup$ Jun 22, 2022 at 18:54
  • 1
    $\begingroup$ The kernel crashes even in version 8.0.4, this seems to be an old bug. $\endgroup$
    – innaiz
    Jun 23, 2022 at 8:41
  • 5
    $\begingroup$ Reporting this as a bug. $\endgroup$ Jun 23, 2022 at 14:45
  • 1
    $\begingroup$ I think you have to contact Tech Support for tracking. As far as I am aware reports filed internally do not have external tracking. We do have a field for "External reporter" but I can only fill it in when a full name is available. (The advantage is that external reporters get notified when fixes are made.) $\endgroup$ Jun 23, 2022 at 19:37
  • 1
    $\begingroup$ It works fine on 13.2.0 on Windows 11. $\endgroup$
    – Ben Izd
    Feb 10, 2023 at 10:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.