Exercise
Random number
Objetive
Create a class RandomNumber, with three static methods:
- GetFloat will return a number between 0 and 1 using the following algorithm:
seed = (seed * a + c) % m
result = abs(seed / m)
- GetInt(max) will return a number from 0 to max, using:
result = round(max * GetFloat)
- GetInt(min, max) will return a number from min to max (you must create this one totally on your own).
The starting values must be:
m = 233280;
a = 9301;
c = 49297;
seed = 1;
Code
Imports System
Namespace Random
Class RandomNumber
Private Shared m As Integer = 233280
Private Shared a As Integer = 9301
Private Shared c As Integer = 49297
Private Shared seed As Integer = 1
Public Shared Function GetFloat() As Single
seed = (seed * a + c) Mod m
Return Math.Abs(seed / m)
End Function
Public Shared Function GetInt(ByVal max As Integer) As Integer
Return 0
End Function
Public Shared Function GetInt(ByVal min As Integer, ByVal max As Integer) As Integer
Return 0
End Function
End Class
End Namespace