RandomNumber method returns same number every time called

前端 未结 2 1312
难免孤独
难免孤独 2021-01-18 06:32

I am trying to generate a different random number every time my RandomNumber method is called from within my for loop. Right now, it returns the same number every time.

2条回答
  •  走了就别回头了
    2021-01-18 07:03

    Instantiate Random once. Call .Next() multiple times on the same instance.

    MSDN:

    The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated

    If you do wish to repeatedly instantiate Random, use a different seed each time.

提交回复
热议问题