I am trying to design a circle of textview whose height and width will be dynamic and should be between 100 to 150 dp.
Now the dynamic values can be of any range but I want it between 100 to 150. for example if I get the dynamic value as 1000 or may be 3000.... I should be able to convert into numbers between 100 to 150.
I am looking for the logic where I input a dynamic value(any range)... I get a integer between 100 to 150.
Asked
Active
Viewed 152 times
-1

Parth Lotia
- 753
- 1
- 7
- 25

jibs
- 3
- 1
- 5
-
can it be random number between 100-150? – Manohar Mar 08 '19 at 06:33
-
possible dublicate of https://stackoverflow.com/questions/5294955/how-to-scale-down-a-range-of-numbers-with-a-known-min-and-max-value – Akash Shah Mar 08 '19 at 06:36
-
simplest way will be `number%50+100` – Manohar Mar 08 '19 at 06:36
-
according to what logic should the input be "converted"? – Stultuske Mar 08 '19 at 06:40
-
Any random value between 100 - 150. – jibs Mar 08 '19 at 07:10
1 Answers
0
If you need a random value between 100 and 150
int low = 100;
int high = 150;
Random random = new Random();
int randomValue = random.nextInt(high - low + 1) + low;
If you need a random value between 100 and 150 based on a given dynamic value.
int dynamicValue = 1000; // or 3000 or any value
int low = 100;
int high = 150;
int randomValue = (dynamicValue % (high - low + 1)) + low;

Son Truong
- 13,661
- 5
- 32
- 58