(A) A byte is restricted to max. 256 distinct values because it is 8 bit wide. (B) The possible problem has been pointed out in an earlier comment by Henry.Ayoola. If you call RandomNumber many times, you get a stream of values which contains only a small subset of 0 ... maxvalue-1. This behaviour can usually not be expected from a RNG.
I don't see it either, unless I'm missing something.
The val variable will contain a double between 0 and 1, depending on the value of the random byte that was generated. Then the maxvalue will be multiplied with a value between 0 and 1 and will thus act as if divided by the number behind the comma. Example: maxvalue = 6, val = 0.2 => return 3. This is 'random' depending on how random the byte is, that is generated by the random.GetBytes function.
Last Visit: 31-Dec-99 18:00 Last Update: 28-Mar-23 8:11