How can I a random number from 25 to 225 by 20? For example: 25, 45 .65 ,85, 105 to 225?
Asked
Active
Viewed 92 times
-2
-
2Are these random numbers? This seems increment of 20. – Adil Aug 29 '16 at 09:26
-
Do you need any of those or all numbers? – MakePeaceGreatAgain Aug 29 '16 at 09:27
-
Yes to random object location !! – Bunthai Deng Aug 29 '16 at 09:36
-
Well, get a random number from 0 to 10, multiply if with 20 and add 25 – ByteHamster Aug 29 '16 at 10:06
2 Answers
1
Random rnd = new Random();
....
int x = rnd.Next(11)*20 + 25; // or .Next(10), if 225 is exclusive

AlexD
- 32,156
- 3
- 71
- 65
-
1
-
1@AlexD Nope - `rand.Next(10)` picks number from `0..9`. It should be `Next(11)` :) – pwas Aug 29 '16 at 09:30
-
0
Create an array of the acceptable values. i.e. 25,45,65, ... 255. Use a random generated number to access the indexes of the array. Get the value at that array index. Happiness and joy abound in the world.

jwpfox
- 5,124
- 11
- 45
- 42