Forum Discussion

tmahender12's avatar
tmahender12
Frequent Contributor
9 years ago

random number

how can i generate random numbers for a alpha numeric text box? in vbscript

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    You can use this function to generate random integers in the Min...Max range:

    Function RandomNumber(Min, Max)
      Randomize
      RandomNumber = Int(Min + Rnd*(Max - Min + 1))
    End Function

    Usage:

    number = RandomNumber(0, 100)
    • Viji123's avatar
      Viji123
      Occasional Contributor
      Function RandomNumber(Min, Max)
        Randomize
        RandomNumber = Int(Min + Rnd*(Max - Min + 1))
      End Function

      I tried to implement this logic using python , its not working 

       

      I tried as below

      def  RandomNumber(Min, Max)
      Randomize
      RandomNumber = Int(Min + Rnd*(Max - Min + 1))

       

      Here am getting error in the second line ie. "Randomize" doesnt exist in python. Please advice

      • baxatob's avatar
        baxatob
        Community Hero
        import random
        
        random.randint(min_, max_) #will return random integer between min_ and max_

         

        In Python you should use a module random to operate random values.