如何找到 bash $RANDOM 特殊变量的手册文档?

How to find manual doc for bash $RANDOM special variable?

在Bash中有一些变量(如$RANDOM)是内置函数。我的理解是 $RANDOM 使用 C 函数 random (例如 man random)。

但我不得不偶然发现这些信息。我希望能够做的是 man $RANDOMtype $RANDOM(甚至 help $RANDOM)之类的事情。

尝试的问题是 $RANDOM 被评估为实际的随机数:-)

那么你如何确定像 $RANDOM 这样的特殊内置变量的实现是什么?除了筛选 Bash 源代码,我只是没有足够的脑力。

肯定有办法让 shell 指示特殊变量的实现方式(例如 "this is a builtin variable that points to a C function of <N> name")

或者可能没有? *耸肩*

任何 help/info 将不胜感激:-)

谢谢!

来自 man bash/RANDOM

RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated.  The sequence of random numbers may be initialized by assigning a value to RANDOM.  If RANDOM is unset, it loses its
       special properties, even if it is subsequently reset.

手册没有说明它是如何实现的。

否则来自 sources:variables.c 表明 RANDOM 链接到函数 get_random

INIT_DYNAMIC_VAR ("RANDOM", (char *)NULL, get_random, assign_random);

调用 get_random_numberseedrandbrand

/* A linear congruential random number generator based on the example
   one in the ANSI C standard.  This one isn't very good, but a more
   complicated one is overkill. */

/* Returns a pseudo-random number between 0 and 32767. */
static int
brand ()
{
  /* From "Random number generators: good ones are hard to find",
     Park and Miller, Communications of the ACM, vol. 31, no. 10,
     October 1988, p. 1195. filtered through FreeBSD */
  long h, l;

  /* Can't seed with 0. */
  if (rseed == 0)
    rseed = 123459876;
  h = rseed / 127773;
  l = rseed % 127773;
  rseed = 16807 * l - 2836 * h;
#if 0
  if (rseed < 0)
    rseed += 0x7fffffff;
#endif
  return ((unsigned int)(rseed & 32767));       /* was % 32768 */
}