python - Using 'If' to run the loop again? -
I'm producing 2 arrays of random numbers from 3 to 3 (this is my x and y coordinate accordingly ). However, if I use a loop related to X and Y over my radius (which is 3) then what is the need to create a new set of numbers? If I take this loop to get it after my loop? thanks Most random library modules have a regular interval [0,1] but to return a floating point number from the same distribution. To choose randomly from an equal distribution on the [a, b] interval, where B & gt; One, you can only multiply by I'm not sure which modules you are importing in your example, so I give examples using standard random modules, as well as numpy.random < Strong> random numpy.random Nampee allows one to work for speed and clarity . Import as imported NP DP Rand_Angase (A, B, Size): a + np.random.random (size) * (B - A) x = rand_range (-3, Return to 3, (3)) y = rand_range (3, 3, (3)) Or, create a 2D array of 2 rows of 3 elements, and use unpacking Check the border The criteria for having the points generated with x, y = (0, 0), 3 units of y to make sure something similar can do: Looking at the underlying random method one At the interval [0,1], these arrays should undergo all the following affirmations: ba , and then add
a .
import random def rand_range (a, b): i + rand_range (-3, 3) for range i = in category i for a + Return random.uniform () * (b - a) x = [rand_range (-3, 3) I (3)]
x, y = Rand_range (-3, 3, (2, 3))
x = [ ] y = [] for the range i (3): x i, yi = 3, 3 # while examining basically determined candidates, xi ** 2 + yi ** 2 & gt; 9: xi = rand_range (-3, 3) yi = rand_range (-3, 3) x.append (xi) y.append (yi)
For xi, yi in zip (x, y): xi ** 2 + yi ** Emphasis 2 & lt; = 9
Comments
Post a Comment