+ 1

if someone can explain this problem

Declare a variable X that stores a list of 100 integers randomly sampled between -25 and 25. I know how to create an empty and to append to that list but I don t know how I generate that numbers to be in total 100 , if we know that lenght of that renge is just 50

24th Sep 2022, 3:40 PM
Andrei Macovei
Andrei Macovei - avatar
4 Réponses
+ 2
You can use the built-in random library also. random.choices(range(-25,26), k=100) https://code.sololearn.com/ckK4JLBVwSYK/?ref=app
24th Sep 2022, 5:06 PM
Tibor Santa
Tibor Santa - avatar
0
#For example using numpy: import numpy as np print(np.random.randint(-25, 25+1, 100))
24th Sep 2022, 3:54 PM
Lisa
Lisa - avatar
0
and can be do without Numpy or Scipy?
24th Sep 2022, 4:13 PM
Andrei Macovei
Andrei Macovei - avatar
0
You would need to write your own algorithm to generate (pseudo)random numbers if you don't want to use libraries (edited)
24th Sep 2022, 4:43 PM
Lisa
Lisa - avatar