Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: %random%  (Read 4928 times)

0 Members and 1 Guest are viewing this topic.

wowmaniac123

    Topic Starter


    Rookie

    %random%
    « on: February 19, 2010, 09:36:11 PM »
    Im trying to create a batch program that will tell me a random thing everyday. I am wondering if I can set parameters on the random function. Just Percents Random seems to give me 6 digit numbers. Can I make %random% give me only a number between 1 and 50 or something like that?

    greg



      Intermediate

      Thanked: 7
      Re: %random%
      « Reply #1 on: February 20, 2010, 02:24:49 AM »
       http://www.randomizer.org/form.htm
       

            Research Randomizer Results

      1 Set of 5 Unique Numbers Per Set
      Range: From 1 to 50 -- Unsorted


      Job Status:

         Set #1:
       13, 1, 19, 3, 39
       


      ------------------------------------------

      Microsoft Windows XP [Version 5.1.2600]
      (C) Copyright 1985-2001 Microsoft Corp.

      C:\>echo %random%
      1646

      C:\>echo %random%
      20204

      C:\>echo %random%
      15365

      C:\>echo %random%
      18866

      C:\>echo %random%
      26543

      C:\>
        

      Have a Nice Day

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: %random%
      « Reply #2 on: February 20, 2010, 02:51:41 AM »
      Quote
      C:\>echo %random%
      1646

      C:\>echo %random%
      20204

      C:\>echo %random%
      15365

      C:\>echo %random%
      18866

      C:\>echo %random%
      26543

      This is either the new math or just plain fuzzy math, but none of the results appear to be between 1 and 50. 

      Code: [Select]
      @echo off
      set /a rnd=%random% %% 50 + 1
      echo Random number between 1 and 50 is %rnd%

      Good luck.  8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      greg



        Intermediate

        Thanked: 7
        Re: %random%
        « Reply #3 on: February 20, 2010, 07:52:42 AM »
           Set #1:
         13, 1, 19, 3, 39
        Have a Nice Day

        Salmon Trout

        • Guest
        Re: %random%
        « Reply #4 on: February 20, 2010, 07:56:50 AM »
        so, greg, how does that answer the OP's question?

        greg



          Intermediate

          Thanked: 7
          Re: %random%
          « Reply #5 on: February 20, 2010, 08:08:03 AM »
          C:\>type rand.bat
          Code: [Select]
          @echo off
          set /a rnd=%random% %% 50 + 1
          echo Random number between 1 and 50 is %rnd%


          Output:
          C:\>rand.bat

          Random number between 1 and 50 is 39

          C:\>rand.bat
          Random number between 1 and 50 is 22

          C:\>rand.bat
          Random number between 1 and 50 is 39

          C:\>rand.bat
          Random number between 1 and 50 is 28

          C:\>rand.bat
          Random number between 1 and 50 is 7

          C:\>
          Have a Nice Day

          greg



            Intermediate

            Thanked: 7
            Re: %random%
            « Reply #6 on: February 20, 2010, 10:57:17 AM »
            Can I make %random% give me only a number between 1 and 50 or something like that?

            Wowmaniac123,

            You may ignore many posters who pretend they are Computer Hope Staff Moderators.  They should contact you by email when they are off Topic.

            I believe Sidewinder ( Post #2 this thread ) demonstrated the correct way to use %random%, the random number generator, for numbers less that 50.

            Good luck with your project
            Have a Nice Day

            Carbon Dudeoxide

            • Global Moderator

            • Mastermind
            • Thanked: 169
              • Yes
              • Yes
              • Yes
            • Certifications: List
            • Experience: Guru
            • OS: Mac OS
            Re: %random%
            « Reply #7 on: February 24, 2010, 07:15:38 PM »
            Not sure what you're on about, Greg....but Sidewinder's got it.

            tommyroyall



              Rookie

              Thanked: 1
              Re: %random%
              « Reply #8 on: February 24, 2010, 07:36:06 PM »
              Coolness 8). I was just about to ask this question   :(