Arithmetic operation resulted in an overflow

Ruffone
Ruffone used Ask the Experts™
on
Trying to create a random number with this line of code but it gives me this error. This is the number it creates "634732955157479720"

Private Shared randomNumGen As Random = New System.Random(CLng(DateTime.Now.Ticks - DateTime.Now.Millisecond))

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
This fixed it for me

Private Shared random As New Random(CInt(DateTime.Now.Ticks And Integer.MaxValue))

Open in new window

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial