math.random() follows which algorithms

前端 未结 5 1570
盖世英雄少女心
盖世英雄少女心 2021-01-03 03:47

Am using math.random() method to generate random numbers. but i had a doubt about that method. math.random() is which algorithms will fallow to generate random

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 04:22

    Use java.util.Random API

    An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 3, Section 3.2.1.)

    Algorithm class : pseudorandom number generator known as PRNG. You can read more about it here.

    Note : Math.random() also uses java.util.Random instance to generate the psuedo-random numbers internally

提交回复
热议问题