Forum Thread: Using Decimals with Randint()

Right now I'm working on making Python "type" on your screen (I was feeling bored and experimental), and I got this far on my own, but I can't find any way to use decimals in my script, as Python only accepts whole numbers for randint().

#include <stdio.h>;
import sys;
import time;
import os;
import random;

script = "I just really need to type something right now. I'm not sure why, but I really feel like typing on the Chromebook right now. It seems kinda weird, but I like doing this. It helps me practice what I'm doing. I've noticed that I'm a lot worse at typing lately, and I don't know why. Maybe it's because I've been working with a chunky keyboard, and these Chromebook keyboards are extremely thin. Yup, this is actually entertaining for me. I'm not exactly sure why I want to do this, but I just do. It's almost addicting to me, and I don't know why.\n";

for i in range(0, 587):
time_num = random.randint(0.1, 0.4);

The output I get is:
"ITraceback (most recent call last):
File "", line 11, in <module>
time_num = random.randint(0.1, 0.4);
File "/usr/lib64/python2.7/", line 242, in randint
return self.randrange(a, b+1)
File "/usr/lib64/python2.7/", line 187, in randrange
raise ValueError, "non-integer arg 1 for randrange()"
ValueError: non-integer arg 1 for randrange()

Any ideas?

EDIT: Don't tell me how to make this simpler, as this was just for learning.

5 Responses


Thats what i also found ( But i guess Ciuffy got it first :) )
Hope it helps ...

# Sergeant

I did not explain how to round the number, which is extremely useful, GG.

Share Your Thoughts

  • Hot
  • Active