GENIUS One-Liner For Generating Random Numbers In Python 😳

preview_player
Показать описание
Genius one-liner for generating a list of random numbers in #Python. #Shorts
Рекомендации по теме
Комментарии
Автор

The actual one-liner for this would be
print([__import__("random").randint(1, 100) for _ in range(100)])

asgard_
Автор

One liner: proceeds to use 4 lines at minimum

altairbueno
Автор

import random;print(random.sample(range(100), k=100))

anuragtewary
Автор

If you use semicolons you can make a whole program only needing one line (just some inspiration for the next video)

PhilippLackner
Автор

Meanwhile in R:

sample(0:100, 100)

the_linguist_ll
Автор

Use generators whenever possible. They are lazily evaluated, meaning that only a single number is taken up in memory at a time instead of the whole list. i.e., if you're using this list in a for loop and aren't going to loop over it more than once. You make a generator by using "()" instead of "[]"

grantpeterson
Автор

Rn = random.sample(list(range(100)), 100)
Print (rn)

mauro
Автор

Awesome tip definitely needed this before I coded cows and bulls but still it’s good to know

YungHurdy
Автор

when random number generator in python is already one liner

white_
Автор

Only true geniuses know that randint has an argument called "size" and numpy array has a tolist() to convert numpy array to list if needed

abir
Автор

wow!!! genius!!!! one in a million!!! no one could every come up with that!!!!

jjophoven
Автор

Is there a way of ensuring each number is only generated once?

dansmith
Автор

Bro why not use numpy random number generators the syntax requires no for loop

jonah
Автор

so what are the odds of getting the 100 numbers to go in perfect ascending order?

kingjames
Автор

What’s genius about this? I thought you would show the genius solution after the normal one but you just showed the normal one??

dominobuilder
Автор

Does thia generate true random numbers or do the numbers follow uniform distribution??

amankumarjaiswar
Автор

That's not genius at all... Don't use list comprehension when there are dedicated functions for that.

Ghost-Raccoon
Автор

Me chilling with node.js math.floor(math.random())

yicha
Автор

Doesn't np.random.randint() take a size input as well?
So you call it with size=10 and it'll generate a 1d-array of that size

suhailmall
Автор

How would you make this without duplicates?

benedictnwani
join shbcf.ru