Reputation: 61
When using random.randint() in this form, I can't get integer division to work:
(random.randint(-40, 215) - -40) // (215 - -40)
This returns 0, however something like this returns correctly:
random.randint(3,5) - 2 // 2
How do I format the first equation correctly to get a rounded integer instead of defaulting to 0?
Upvotes: 0
Views: 229
Reputation: 1
In case you want the non int answer
print (random.randint(-40, 215) +40.0) / (215+40)
The result lies always between (0,1)
step of which is always 0 and hence it returns always zero.
Upvotes: 0
Reputation: 61
In case someone runs into this when normalizing integers, here is a normalization between -40 and 215:
(random.randint(-40,215) - -40.0) * 10 // (215.0 - -40.0) * 10
Kudos to Willem Van Onsem
Upvotes: 1