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;
os.system("clear");
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):
sys.stdout.write(str(script[i]));
sys.stdout.flush();
time_num = random.randint(0.1, 0.4);
time.sleep(time_num);
The output I get is:
"ITraceback (most recent call last):
File "main.py", line 11, in <module>
time_num = random.randint(0.1, 0.4);
File "/usr/lib64/python2.7/random.py", line 242, in randint
return self.randrange(a, b+1)
File "/usr/lib64/python2.7/random.py", 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
Random.uniform (nf, nf)
It's part of the lower commands used by random generator, e.g. randint () calls for randrange().
Hope this helped.
Resource: https://docs.python.org/2/library/random.html
Perfect! Thanks Ciuffy!
Cracker:
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.
Ciuffy:
Thanks
# Sergeant
Share Your Thoughts