<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Segoe UI Emoji";
panose-1:2 11 5 2 4 2 4 2 2 3;}
@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hi, my name is Terry, and I’d like to propose a small function that could be added into the Python’s “random” module.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This function is for generating a random float/decimal number. I would like to know if there’s such function that does the same thing, if there is, please point out to me. If not, I would like to ask you developers to add this function into future Python versions.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The function code is as follow:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>from random import *<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>def randfloat(x , y , maxfloatpt=None):<o:p></o:p></p><p class=MsoNormal> if x > y:<o:p></o:p></p><p class=MsoNormal> x , y = y , x<o:p></o:p></p><p class=MsoNormal> lenx = len(str(x))<o:p></o:p></p><p class=MsoNormal> leny = len(str(y))<o:p></o:p></p><p class=MsoNormal> intx = int(x)<o:p></o:p></p><p class=MsoNormal> inty = int(y)<o:p></o:p></p><p class=MsoNormal> bigger = max(lenx,leny)<o:p></o:p></p><p class=MsoNormal> if maxfloatpt == None:<o:p></o:p></p><p class=MsoNormal> if bigger == lenx:<o:p></o:p></p><p class=MsoNormal> intxlen = len(str(intx))<o:p></o:p></p><p class=MsoNormal> maxfloatpt = len(str(x)[intxlen:])<o:p></o:p></p><p class=MsoNormal> elif bigger == leny:<o:p></o:p></p><p class=MsoNormal> intylen = len(str(inty))<o:p></o:p></p><p class=MsoNormal> maxfloatpt = len(str(y)[intylen:])<o:p></o:p></p><p class=MsoNormal> else:<o:p></o:p></p><p class=MsoNormal> pass<o:p></o:p></p><p class=MsoNormal> else:<o:p></o:p></p><p class=MsoNormal> pass<o:p></o:p></p><p class=MsoNormal> num = randint(intx , inty)<o:p></o:p></p><p class=MsoNormal> num = str(num)<o:p></o:p></p><p class=MsoNormal> num = '%s.' % num <o:p></o:p></p><p class=MsoNormal> for i in range(0 , maxfloatpt):<o:p></o:p></p><p class=MsoNormal> flnum = randint(0 , 9)<o:p></o:p></p><p class=MsoNormal> str(flnum)<o:p></o:p></p><p class=MsoNormal> num = '%s%s' % (num , flnum)<o:p></o:p></p><p class=MsoNormal> return float(num)<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal style='text-indent:10.2pt'>P.S.: If the indent has anything wrong, just correct me, thx!<o:p></o:p></p><p class=MsoNormal style='text-indent:10.2pt'><o:p> </o:p></p><p class=MsoNormal>P.P.S.: The function is tested, it’s working <span style='font-family:"Segoe UI Emoji",sans-serif'>😊</span><o:p></o:p></p></div></body></html>