Random number generator in Python

Поділитися
Вставка
  • Опубліковано 27 жов 2020
  • In this video, you will learn how to generate random numbers in python using the random module.
    We will understand each method in detail with examples.
    source code : theprogrammingportal.com/Pyth...
    GIT : github.com/TheProgrammingPort...
    Random module - docs.python.org/3/library/ran...
    Random() - docs.python.org/3/library/ran...
    Randint() - docs.python.org/3/library/ran...
    Randrange() - docs.python.org/3/library/ran...
    Uniform() - docs.python.org/3/library/ran...
    Sample() - docs.python.org/3/library/ran...
    Shuffle() - docs.python.org/3/library/ran...
    Choice() - docs.python.org/3/library/ran...
    Python tutorial - docs.python.org/3/tutorial/in...
    In this video you will learn:
    - how to generate random numbers in python
    - random module in python
    - range function in python
    - importing random module in python
    - python built in function
    - Random method
    - Randint method
    - Randrange method
    - Uniform method
    - Sample method
    - Shuffle method
    - Choice method
    Want to learn more from me?
    Python examples complete Playlist :
    • python program for str...
    Java examples complete Playlist :
    • Java Factorial Program
    #PythonProgramForRandomNumber
    #PythonTutorialForBeginners
    #PythonTutorial
    #RandomNumberGeneratorInPython
    #RandomNumberProgramInPython
    #PythonExamples
    #RandomNumber
    Subscribe to my other channel for random videos:
    IndianBox : / @indianbox1736
    Follow us on:
    Facebook : / theprogrammingportal
    Instagram : / theprogrammingportal
    Support:
    Patreon : / theprogrammingportal
    Keep Coding!

КОМЕНТАРІ • 50

  • @fasty93
    @fasty93 Рік тому +3

    I am learning python and I wanted to create a variable input that is random, and it works! all thanks to you!

  • @NateCody
    @NateCody 2 роки тому +10

    Thanks so much! I needed this for a project I’ve been working on

  • @soloxballer
    @soloxballer 2 роки тому +6

    Thank you man I was looking for the random float and you were the only guy who had it

  • @shqckwave8085
    @shqckwave8085 Рік тому

    Thanks so much I really needed randrange and this is the first one that helped me find out.

  • @melissaleigh8019
    @melissaleigh8019 4 місяці тому

    God bless you, passing on your knowledge to many people.

  • @nov3m472
    @nov3m472 Рік тому +6

    in the beginning i understood "Hi there, iam russian and welcome to programming putin" 🗿

  • @Tooobiasss0
    @Tooobiasss0 21 день тому +1

    great video, helped a lot!

  • @aaryankumar7395
    @aaryankumar7395 Рік тому

    how can we store maximum value of random function in a variable like i want to store the highest value of function in a variable so which command should we use

  • @malvis8737
    @malvis8737 Рік тому +1

    how do I create a random number in a normal distribution with standard deviation and media ?

  • @karenrodrigues5173
    @karenrodrigues5173 2 роки тому +2

    Is there a way to generate ids without importing the random module?

  • @AlekWCcom
    @AlekWCcom Рік тому

    thanks for the simple turturial. it is very usefull and eesy to understand

  • @K_EN_VisheshSaini
    @K_EN_VisheshSaini 2 роки тому +1

    Is there any way to generate random numbers from scratch without using libraries in python?

  • @deemanthreddymokireddy1411
    @deemanthreddymokireddy1411 Рік тому

    Thanks a lot its really helpful

  • @ahmedtaman4572
    @ahmedtaman4572 2 роки тому

    How to generate a fixed float random numbers in a specific range and make sure these numbers do not change with successive runs?!

  • @noguy31
    @noguy31 2 місяці тому

    how do you get to do the pop up of the arguments you can input when you type

  • @kychemclass5850
    @kychemclass5850 Рік тому

    Thank you for your effort.

  • @marcelamaldonado9645
    @marcelamaldonado9645 Рік тому

    thank youuu!!! so helpful!!....

  • @ShauryaTrivedi10
    @ShauryaTrivedi10 Рік тому +1

    It helps me a lot

  • @AlexanderCortes210486
    @AlexanderCortes210486 11 місяців тому +1

    👍 very nice explanation

  • @tristanheck2209
    @tristanheck2209 3 роки тому

    thanks.
    I was looking for random float between given range 3:35.

    • @TheProgrammingPortal
      @TheProgrammingPortal  3 роки тому +1

      Glad it helped you.

    • @tristanheck2209
      @tristanheck2209 3 роки тому

      @@TheProgrammingPortal yeah, you explained it well.
      I'm using it to spawn obstacles on random positions in my prototype. will propably use it much more in the future

  • @CuteAnimals650
    @CuteAnimals650 2 роки тому

    This video is helpful

  • @kp_broz
    @kp_broz 3 роки тому +2

    Thank you❤

  • @roshunluchman4976
    @roshunluchman4976 8 місяців тому

    Hi can anybody tell me how to tell python to randomly choose 6 numbers from a range of say 1 to 10 but it cannot choose a number more than once

  • @theentirestateofalaska.4983
    @theentirestateofalaska.4983 2 роки тому

    Hey man I used the uniform method but I only want it to be a number such as 42.69 instead of 4.496596222329886 so how can I do that.

    • @TheProgrammingPortal
      @TheProgrammingPortal  2 роки тому +3

      Hi,
      Once you get some values form uniform eg. 4.475276262727, use round method or use .format - %.2f .on uniform result. This will help for number of decimal or precision you want to take.
      Refer format method
      docs.python.org/3/tutorial/inputoutput.html
      Round method
      docs.python.org/3/library/functions.html#round
      Hope this helps.

  • @softiceoriginal
    @softiceoriginal Рік тому

    I think:
    import random
    for i in range(1, 10000):

    numList = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
    random.shuffle(numList)
    print(random.choice(numList))

  • @irshadbaruah7961
    @irshadbaruah7961 2 роки тому

    How to plot this random number to visualise

  • @user-nv3sb5hr2f
    @user-nv3sb5hr2f 2 місяці тому

    thanks much

  • @infotricks2589
    @infotricks2589 2 роки тому

    It's very interesting 🥰🥰

  • @oriokotdavid1983
    @oriokotdavid1983 Рік тому

    great

  • @sokaribobaruch3103
    @sokaribobaruch3103 Рік тому

    Thanks

  • @salsailhammita886
    @salsailhammita886 2 роки тому +1

    Thank you

  • @PawanMishra-zt3vb
    @PawanMishra-zt3vb 3 роки тому +1

    If I want to generate random real values in exponential format ,what can I do ??
    Like : - 0.000123223e-14,
    0.13343232323+02

    • @TheProgrammingPortal
      @TheProgrammingPortal  3 роки тому +1

      I guess you can use numpy library which has exponential random method functionality.

    • @PawanMishra-zt3vb
      @PawanMishra-zt3vb 3 роки тому +1

      @@TheProgrammingPortal Actually I want the random real values population at the same time I want to make sure that these population are really under Min ,max bounds

  • @kofiswisconsin1552
    @kofiswisconsin1552 5 місяців тому

    👍

  • @rahulbene1754
    @rahulbene1754 Рік тому

    👍👍👍

  • @thezanecampbell
    @thezanecampbell 2 роки тому

    👏👍💯

  • @BHARAT_TECH23
    @BHARAT_TECH23 2 роки тому

    Tq u sir but this video is not sufficient for all concept pls make 1,2 videos more in this topic

    • @TheProgrammingPortal
      @TheProgrammingPortal  2 роки тому +1

      Thank you for the feedback. Will surely try to add few more videos in future.

  • @dhhdggvvd2978
    @dhhdggvvd2978 Рік тому

    How about Random alphabets, words...

    • @TheProgrammingPortal
      @TheProgrammingPortal  Рік тому

      Hi,
      There are a few ways you can do it with existing choices method from random modules.
      One way to have AtoZ characters with upper or lower case in variable and use that in random.choice() this is randomly choose one character from it.
      Let's say you need word of specific length, eg. Length of 10, then use for loop to generate and append in string.
      This loop can be further written using list comprehension.
      Data="avshshsbjuwhwbsjsj" # your set of characters
      Something like below.
      .join((random.choice(Data)) for x in range(10))
      Instead of using defined characters in a variable, you can explore string methods in string.ascii uppercase or lowercase.
      Refer docs.python.org/2/library/string.html
      Hope this gives enough idea to look it.