  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Generate a random number in interval [0,360) which is divisible by number 15  » java » Generate a random number in interval [0,360) which is divisible by number 15

By : Brian Keefe
Date : November 21 2020, 07:01 PM
I wish did fix the issue. Welcome to SO Michal!
One easy way to accomplish this is to generate a random number less than 24 (=360/15), then multiply the result by 15: code :
``````(int)(Math.random()*24)) * 15;
`````` ## Generate a random number NOT divisible by x?

By : fmedia
Date : March 29 2020, 07:55 AM
To fix the issue you can do I'm using rand(1..10) * 3 to generate a random number divisible by three.
code :
``````k = rand(0..1000)
out = k + k/2 + 1 # The '/' here is integer division.

0 -> 1
1 -> 2
2 -> 4
3 -> 5
4 -> 7
5 -> 8
6 -> 10
...
`````` ## How to generate a random number in the interval (0.8 ; 1)?

By : slim
Date : March 29 2020, 07:55 AM
this one helps. Math.random() gives a pseudorandom number on the interval (0 ; 1]. But I wanted to generate in other intervals, such as, (0.5 ; 0.6) or (0.7; 1] or (0.8 ; 1) etc.
code :
``````import java.util.concurrent.ThreadLocalRandom;

public class MyClass {
public static void main(String args[]) {
}
}
`````` ## How to generate a random number that is evenly divisible by another randomly generated number

By : Denae
Date : March 29 2020, 07:55 AM
seems to work fine I'm working on a simple math flashcards app using JavaScript and jQuery. The available operations are addition, subtraction, multiplication, and division, each of which have functions that use generateTop() and generateBottom() to assign values to HTML elements. , Just add a single if statement to make your function recursive:
code :
``````function generateBottom(max, min) {
bottomNumber = Math.floor(Math.random() * (max - min) + min);
if (topNumber % bottomNumber) {
generateBottom(max, min);
}
return bottomNumber;
}
`````` ## Generate list of random number with the sum divisible by n

By : user3194513
Date : March 29 2020, 07:55 AM
I hope this helps . My concern was what is a good way to generate a list of 10 - 15 numbers that the sum of them always divisible by n. , An improvement on @SamerAyoub using numpy:
code :
``````import numpy as np

n, m, k= 3, 9, 15
arr = np.empty(k, dtype = int)
arr[1:] = np.random.choice(np.arange(0, m), k-1)
rem = arr[1:].sum() % n
arr  = np.random.choice(np.arange(n - rem, m, n))

print(''.join([str(i) for i in arr]))
print(arr.sum()%n == 0)

374564205252063
True
``````
``````def slow_way(n, m, k):
arr = np.empty(k)
while arr.sum() % n != 0:
arr = np.random.choice(np.arange(0, m), k)
return arr
`````` ## Generate a random number which is divisible by 10

By : raju chekuri
Date : March 29 2020, 07:55 AM
like below fixes the issue Calculate an integer random number between 1 and 5, and multiply it by 10.
There are lots of tutorials out there on how to accomplish the first task. E.g., use 