RandomNumber method returns same number every time called

前端 未结 2 1315
难免孤独
难免孤独 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.

    0 讨论(0)
  • 2021-01-18 07:14

    There's nothing saying a truly random sequence can't be the same number each time! :-) There is a small probability it's legit so you can never truly be sure. ducks for cover

    0 讨论(0)
提交回复
热议问题