473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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_vezes[-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
Jun 27 '08 #1
4 1959
lu******@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_vezes[-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

Jun 27 '08 #2
Le Sunday 15 June 2008 20:23:56 lu******@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_vezes[-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
Jun 27 '08 #3

<lu******@gmail.comwrote in message
news:6e**********************************@j22g2000 hsf.googlegroups.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_vezes[-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

Jun 27 '08 #4
On 15 Jun, 21:05, "Terry Reedy" <tjre...@udel.eduwrote:
<luisl...@gmail.comwrote in message

news:6e**********************************@j22g2000 hsf.googlegroups.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_vezes[-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.criarAleatorio()
File "individuo.py", line 247, in criarAleatorio
self.criarTr2_vezes()
File "individuo.py", line 185, in criarTr2_vezes
self.tr2_vezes = self.rr(self.d_tr2_vezes[0],self.d_tr2_vezes[-1],
1)
File "/usr/lib/python2.5/random.py", line 158, in randrange
istart = int(start)
KeyboardInterrupt

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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: JustSomeGuy | last post by:
I have a need to make an applicaiton that uses a variable number of nested for loops. for now I'm using a fixed number: for (z=0; z < Z; ++z) for (y=0; y < Y; ++y) for (x=0; x < X; ++x)
17
by: John Salerno | last post by:
I'm reading Text Processing in Python right now and I came across a comment that is helping me to see for loops in a new light. I think because I'm used to the C-style for loop where you create a...
10
by: Putty | last post by:
In C and C++ and Java, the 'for' statement is a shortcut to make very concise loops. In python, 'for' iterates over elements in a sequence. Is there a way to do this in python that's more concise...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.