randrange loops

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • luislupe@gmail.com

    randrange loops

    Hi,


    I've created a method where the script defines twenty variables and
    several of them should be random having a maximum and a minimum value.

    What I did was this:

    from random import randrange as rr, random

    self.tr2_vezes = self.rr(self.d_ tr2_vezes[0],self.d_tr2_vez es[-1],
    1) # just an example, others are similar

    The minimum and maximum limits are never lower than -50 and higher
    than 250 and are integer.

    Many times, not always, the problem is that the script just loops
    forever and no value is chosen for the variable.

    What's happening here? What am I doing wrong?

    Thank you for any help.


    Luis
  • Peter Otten

    #2
    Re: randrange loops

    luislupe@gmail. com wrote:
    I've created a method where the script defines twenty variables and
    several of them should be random having a maximum and a minimum value.
    >
    What I did was this:
    >
    from random import randrange as rr, random
    >
    self.tr2_vezes = self.rr(self.d_ tr2_vezes[0],self.d_tr2_vez es[-1],
    1) # just an example, others are similar
    >
    The minimum and maximum limits are never lower than -50 and higher
    than 250 and are integer.
    >
    Many times, not always, the problem is that the script just loops
    forever and no value is chosen for the variable.
    >
    What's happening here? What am I doing wrong?
    You don't provide enough information. Please show as a small script that
    demonstrates the behaviour you describe.

    Peter

    Comment

    • =?iso-8859-1?q?C=E9dric_Lucantis?=

      #3
      Re: randrange loops

      Le Sunday 15 June 2008 20:23:56 luislupe@gmail. com, vous avez écrit :
      Hi,
      >
      >
      I've created a method where the script defines twenty variables and
      several of them should be random having a maximum and a minimum value.
      >
      What I did was this:
      >
      from random import randrange as rr, random
      >
      self.tr2_vezes = self.rr(self.d_ tr2_vezes[0],self.d_tr2_vez es[-1],
      1) # just an example, others are similar
      self.rr ? is it a typo or some method you defined yourself ?
      >
      The minimum and maximum limits are never lower than -50 and higher
      than 250 and are integer.
      >
      Many times, not always, the problem is that the script just loops
      forever and no value is chosen for the variable.
      >
      What's happening here? What am I doing wrong?
      >
      as it's very unlikely to be a bug in the randrange function I'd say something
      is wrong with your script but we'll need more infos to help. Can you post the
      whole function ?

      --
      Cédric Lucantis

      Comment

      • Terry Reedy

        #4
        Re: randrange loops


        <luislupe@gmail .comwrote in message
        news:6e424f2a-872d-4dd1-b28d-cf2a985895c9@j2 2g2000hsf.googl egroups.com...
        | Hi,
        |
        |
        | I've created a method where the script defines twenty variables and
        | several of them should be random having a maximum and a minimum value.
        |
        | What I did was this:
        |
        | from random import randrange as rr, random
        |
        | self.tr2_vezes = self.rr(self.d_ tr2_vezes[0],self.d_tr2_vez es[-1],
        | 1) # just an example, others are similar

        Are we to presume that self.rr is rr?

        | The minimum and maximum limits are never lower than -50 and higher
        | than 250 and are integer.
        |
        | Many times, not always, the problem is that the script just loops
        | forever and no value is chosen for the variable.
        |
        | What's happening here? What am I doing wrong?

        On what line does it 'loop forever'?
        Are you saying that the same code with same input sometimes works and
        sometimes does not? In any case, try to reduce it to the minumum that
        either always or sometimes fails. And post that.

        tjr



        Comment

        • luislupe@gmail.com

          #5
          Re: randrange loops

          On 15 Jun, 21:05, "Terry Reedy" <tjre...@udel.e duwrote:
          <luisl...@gmail .comwrote in message
          >
          news:6e424f2a-872d-4dd1-b28d-cf2a985895c9@j2 2g2000hsf.googl egroups.com...
          | Hi,
          |
          |
          | I've created a method where the script defines twenty variables and
          | several of them should be random having a maximum and a minimum value.
          |
          | What I did was this:
          |
          | from random import randrange as rr, random
          |
          | self.tr2_vezes = self.rr(self.d_ tr2_vezes[0],self.d_tr2_vez es[-1],
          | 1) # just an example, others are similar
          >
          Are we to presume that self.rr is rr?
          >
          | The minimum and maximum limits are never lower than -50 and higher
          | than 250 and are integer.
          |
          | Many times, not always, the problem is that the script just loops
          | forever and no value is chosen for the variable.
          |
          | What's happening here? What am I doing wrong?
          >
          On what line does it 'loop forever'?
          Are you saying that the same code with same input sometimes works and
          sometimes does not? In any case, try to reduce it to the minumum that
          either always or sometimes fails. And post that.
          >
          tjr

          I tried to reproduce the error in a small script. Python's error
          message always returned this kind of error:

          Traceback (most recent call last):
          File "individuo. py", line 584, in <module>
          ind.criarAleato rio()
          File "individuo. py", line 247, in criarAleatorio
          self.criarTr2_v ezes()
          File "individuo. py", line 185, in criarTr2_vezes
          self.tr2_vezes = self.rr(self.d_ tr2_vezes[0],self.d_tr2_vez es[-1],
          1)
          File "/usr/lib/python2.5/random.py", line 158, in randrange
          istart = int(start)
          KeyboardInterru pt

          I got mislead by this. The loop was about a while statement that
          compared values from two of the random variables. It was a '>=' and
          it should be a '>'.

          Thank you for your messages.


          Luis

          Comment

          Working...