Python论坛  - 讨论区

标题:[python-chinese] python怎么生成3位随机数?

2007年03月12日 星期一 10:44

Chao Xu dreamerx2004在gmail.com
星期一 三月 12 10:44:08 HKT 2007

ÎÒÊÇÐÂÊÖ£¬ÓÃʲô·½·¨Éú³ÉÒ»¸ö3λµÄËæ»úÊý£¿
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/14eed250/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 10:49

东子 hydonlee在gmail.com
星期一 三月 12 10:49:06 HKT 2007

使用random库.

EX:

>>> import random
>>> random.randint(100, 999)
563

在07-3-12,Chao Xu <dreamerx2004 at gmail.com> 写道:
>
>  我是新手,用什么方法生成一个3位的随机数?
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>



-- 
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/9919bb24/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 10:51

kergee!z kergee在gmail.com
星期一 三月 12 10:51:23 HKT 2007

如果是整数,random.randint(100,999),如果是浮点数,大概只能自己用random.random()生成了。

在07-3-12,Chao Xu <dreamerx2004在gmail.com> 写道:
>
>  我是新手,用什么方法生成一个3位的随机数?
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/e6f6ba66/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:01

Chao Xu dreamerx2004在gmail.com
星期一 三月 12 14:01:44 HKT 2007

要是001呢?
  ----- Original Message ----- 
  From: kergee!z 
  To: python-chinese在lists.python.cn 
  Sent: Monday, March 12, 2007 10:51 AM
  Subject: Re: [python-chinese]python怎么生成3位随机数?


  如果是整数,random.randint(100,999),如果是浮点数,大概只能自己用random.random()生成了。


  在07-3-12,Chao Xu <dreamerx2004在gmail.com> 写道: 
    我是新手,用什么方法生成一个3位的随机数?

    _______________________________________________
    python-chinese
    Post: send python-chinese在lists.python.cn 
    Subscribe: send subscribe to python-chinese-request在lists.python.cn
    Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
    Detail Info: http://python.cn/mailman/listinfo/python-chinese





------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/9cfd4058/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:03

Deng Patrick-q19285 kedeng在motorola.com
星期一 三月 12 14:03:14 HKT 2007

-_-|||001¾Í²ð³É£³Î»À´·Ö±ðÉú³É¹þ

________________________________

From: python-chinese-bounces在lists.python.cn [mailto:python-chinese-bounces在lists.python.cn] On Behalf Of Chao Xu
Sent: 2007Äê3ÔÂ12ÈÕ 14:02 PM
To: python-chinese在lists.python.cn
Subject: Re: [python-chinese]pythonÔõôÉú³É3λËæ»úÊý£¿


ÒªÊÇ001ÄØ£¿

	----- Original Message ----- 
	From: kergee!z kergee在gmail.com>  
	To: python-chinese在lists.python.cn 
	Sent: Monday, March 12, 2007 10:51 AM
	Subject: Re: [python-chinese]pythonÔõôÉú³É3λËæ»úÊý£¿

	Èç¹ûÊÇÕûÊý£¬random.randint(100,999)£¬Èç¹ûÊǸ¡µãÊý£¬´ó¸ÅÖ»ÄÜ×Ô¼ºÓÃrandom.random()Éú³ÉÁË¡£
	
	
	ÔÚ07-3-12£¬Chao Xu <dreamerx2004在gmail.com> дµÀ£º 

		ÎÒÊÇÐÂÊÖ£¬ÓÃʲô·½·¨Éú³ÉÒ»¸ö3λµÄËæ»úÊý£¿

		_______________________________________________
		python-chinese
		Post: send python-chinese在lists.python.cn 
		Subscribe: send subscribe to python-chinese-request在lists.python.cn
		Unsubscribe: send unsubscribe to   python-chinese-request在lists.python.cn
		Detail Info: http://python.cn/mailman/listinfo/python-chinese
		


	
________________________________


	

	_______________________________________________
	python-chinese
	Post: send python-chinese在lists.python.cn
	Subscribe: send subscribe to python-chinese-request在lists.python.cn
	Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
	Detail Info: http://python.cn/mailman/listinfo/python-chinese

-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/a1ddcfe3/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:08

limodou limodou在gmail.com
星期一 三月 12 14:08:16 HKT 2007

On 3/12/07, Chao Xu <dreamerx2004在gmail.com> wrote:
>
>
> 要是001呢?
>
001不就是1吗?能算是3位整数吗?别和字符串混了吧。

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:23

Sean seantien在gmail.com
星期一 三月 12 14:23:25 HKT 2007

On Mon, 12 Mar 2007 14:08:16 +0800, limodou <limodou在gmail.com> wrote:

> On 3/12/07, Chao Xu <dreamerx2004在gmail.com> wrote:
>>
>>
>> 要是001呢?
>>
> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
>

他的意思可能是像密码锁那样的,三位数。。。。。每个都是从0-9
不是我们理解的数学上的三位数。。。。


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:30

东子 hydonlee在gmail.com
星期一 三月 12 14:30:51 HKT 2007

如果是要生成字串可以这样:

>>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
'713'
>>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
'579'
>>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
'328'

在07-3-12,limodou <limodou at gmail.com> 写道:
>
> On 3/12/07, Chao Xu <dreamerx2004 at gmail.com> wrote:
> >
> >
> > 要是001呢?
> >
> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
>
> --
> I like python!
> UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/eada944f/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:37

amingsc amingsc在gmail.com
星期一 三月 12 14:37:28 HKT 2007

import random
result = ''.join([str(random.randint(0,9)) for i in range(3)])

Sean 写道:
> On Mon, 12 Mar 2007 14:08:16 +0800, limodou <limodou at gmail.com> wrote:
>
>   
>> On 3/12/07, Chao Xu <dreamerx2004 at gmail.com> wrote:
>>     
>>> 要是001呢?
>>>
>>>       
>> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
>>
>>     
>
> 他的意思可能是像密码锁那样的,三位数。。。。。每个都是从0-9
> 不是我们理解的数学上的三位数。。。。
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:39

Hong Yuan hongyuan在homemaster.cn
星期一 三月 12 14:39:13 HKT 2007

Chao Xu 写道:
> 要是001呢?
'%03d' % random.randint(1, 999)

-- 

大管家网上建材超市
装修买建材 上网找大管家
http://www.homemaster.cn
Tel: 0086-21-34240987
Fax: 0086-21-64692422

-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/4d6f1b76/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:41

amingsc amingsc在gmail.com
星期一 三月 12 14:41:05 HKT 2007

random.sample只能进行不重复取样,所以取不出‘001’

东子 写道:
> 如果是要生成字串可以这样:
>
> >>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
> '713'
> >>> ''.join( random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
> '579'
> >>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
> '328'
>
> 在07-3-12,*limodou* <limodou at gmail.com limodou at gmail.com>> 写
> 道:
>
>     On 3/12/07, Chao Xu <dreamerx2004 at gmail.com
>     dreamerx2004 at gmail.com>> wrote:
>     >
>     >
>     > 要是001呢?
>     >
>     001不就是1吗?能算是3位整数吗?别和字符串混了吧。
>
>     --
>     I like python!
>     UliPad <>:
>     http://wiki.woodpecker.org.cn/moin/UliPad
>     My Blog: http://www.donews.net/limodou
>     _______________________________________________
>     python-chinese
>     Post: send python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     Subscribe: send subscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Unsubscribe: send unsubscribe to
>     python-chinese-request at lists.python.cn
>     python-chinese-request at lists.python.cn>
>     Detail Info: http://python.cn/mailman/listinfo/python-chinese
>     <http://python.cn/mailman/listinfo/python-chinese>
>
>
>
>
> -- 
> 只要人间真情在, 何必在意路泥泞
> 时风日下,和谐需要靠暴力达到!!!
> ------------------------------------------------------------------------
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:48

东子 hydonlee在gmail.com
星期一 三月 12 14:48:27 HKT 2007

OK. 受教...

在07-3-12,amingsc <amingsc at gmail.com> 写道:
>
> random.sample只能进行不重复取样,所以取不出'001'
>
> 东子 写道:
> > 如果是要生成字串可以这样:
> >
> > >>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
> > '713'
> > >>> ''.join( random.sample(['0','1','2','3','4','5','6','7','8','9'],
> 3))
> > '579'
> > >>> ''.join(random.sample(['0','1','2','3','4','5','6','7','8','9'], 3))
> > '328'
> >
> > 在07-3-12,*limodou* <limodou at gmail.com limodou at gmail.com>> 写
> > 道:
> >
> >     On 3/12/07, Chao Xu <dreamerx2004 at gmail.com
> >     dreamerx2004 at gmail.com>> wrote:
> >     >
> >     >
> >     > 要是001呢?
> >     >
> >     001不就是1吗?能算是3位整数吗?别和字符串混了吧。
> >
> >     --
> >     I like python!
> >     UliPad <>:
> >     http://wiki.woodpecker.org.cn/moin/UliPad
> >     My Blog: http://www.donews.net/limodou
> >     _______________________________________________
> >     python-chinese
> >     Post: send python-chinese at lists.python.cn
> >     python-chinese at lists.python.cn>
> >     Subscribe: send subscribe to
> >     python-chinese-request at lists.python.cn
> >     python-chinese-request at lists.python.cn>
> >     Unsubscribe: send unsubscribe to
> >     python-chinese-request at lists.python.cn
> >     python-chinese-request at lists.python.cn>
> >     Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >     <http://python.cn/mailman/listinfo/python-chinese>
> >
> >
> >
> >
> > --
> > 只要人间真情在, 何必在意路泥泞
> > 时风日下,和谐需要靠暴力达到!!!
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/9e38d301/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 14:50

Chao Xu dreamerx2004在gmail.com
星期一 三月 12 14:50:52 HKT 2007

Good answer, thanks.

----- Original Message ----- 
From: "amingsc" <amingsc在gmail.com>
To: <python-chinese在lists.python.cn>
Sent: Monday, March 12, 2007 2:37 PM
Subject: Re: [python-chinese] python怎么生成3位随机数?


> import random
> result = ''.join([str(random.randint(0,9)) for i in range(3)])
> 
> Sean 写道:
>> On Mon, 12 Mar 2007 14:08:16 +0800, limodou <limodou在gmail.com> wrote:
>>
>>   
>>> On 3/12/07, Chao Xu <dreamerx2004在gmail.com> wrote:
>>>     
>>>> 要是001呢?
>>>>
>>>>       
>>> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
>>>
>>>     
>>
>> 他的意思可能是像密码锁那样的,三位数。。。。。每个都是从0-9
>> 不是我们理解的数学上的三位数。。。。
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese在lists.python.cn
>> Subscribe: send subscribe to python-chinese-request在lists.python.cn
>> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 15:02

limodou limodou在gmail.com
星期一 三月 12 15:02:18 HKT 2007

那还可以从1-999,然后转为字符串,前面补0就行了。

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 15:03

kergee!z kergee在gmail.com
星期一 三月 12 15:03:04 HKT 2007

如果要生成001,可以用 format = lambda i: "03d" %i

在07-3-12,Chao Xu <dreamerx2004在gmail.com> 写道:
>
> Good answer, thanks.
>
> ----- Original Message -----
> From: "amingsc" <amingsc在gmail.com>
> To: <python-chinese在lists.python.cn>
> Sent: Monday, March 12, 2007 2:37 PM
> Subject: Re: [python-chinese] python怎么生成3位随机数?
>
>
> > import random
> > result = ''.join([str(random.randint(0,9)) for i in range(3)])
> >
> > Sean 写道:
> >> On Mon, 12 Mar 2007 14:08:16 +0800, limodou <limodou在gmail.com> wrote:
> >>
> >>
> >>> On 3/12/07, Chao Xu <dreamerx2004在gmail.com> wrote:
> >>>
> >>>> 要是001呢?
> >>>>
> >>>>
> >>> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
> >>>
> >>>
> >>
> >> 他的意思可能是像密码锁那样的,三位数。。。。。每个都是从0-9
> >> 不是我们理解的数学上的三位数。。。。
> >>
> >> _______________________________________________
> >> python-chinese
> >> Post: send python-chinese在lists.python.cn
> >> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> >> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> >> Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070312/573761ea/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月12日 星期一 15:13

amingsc amingsc在gmail.com
星期一 三月 12 15:13:54 HKT 2007

这个方法不错
result = ('%d'%random.randint(0,999)).rjust(3,'0')

limodou 写道:
> 那还可以从1-999,然后转为字符串,前面补0就行了。
>
>   

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月13日 星期二 08:46

Dreamer dreamerx2004在gmail.com
星期二 三月 13 08:46:11 HKT 2007

Very good anwser! Thank you very much!
  ----- Original Message ----- 
  From: Hong Yuan 
  To: python-chinese在lists.python.cn 
  Sent: Monday, March 12, 2007 2:39 PM
  Subject: Re: [python-chinese] python怎么生成3位随机数?


  Chao Xu 写道: 
    要是001呢?
  '%03d' % random.randint(1, 999)


-- 

大管家网上建材超市
装修买建材 上网找大管家
http://www.homemaster.cn
Tel: 0086-21-34240987
Fax: 0086-21-64692422

------------------------------------------------------------------------------


  _______________________________________________
  python-chinese
  Post: send python-chinese在lists.python.cn
  Subscribe: send subscribe to python-chinese-request在lists.python.cn
  Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
  Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070313/c9e26df0/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月13日 星期二 15:18

Gavin gavin在sz.net.cn
星期二 三月 13 15:18:20 HKT 2007

'%03d'%random.randint(0,999)


----- Original Message ----- 
发件人: "amingsc" <amingsc在gmail.com>
收件人: <python-chinese在lists.python.cn>
发送时间: 2007年3月12日 14:37
主题: Re: [python-chinese] python怎么生成3位随机数?


import random
result = ''.join([str(random.randint(0,9)) for i in range(3)])

Sean 写道:
> On Mon, 12 Mar 2007 14:08:16 +0800, limodou <limodou在gmail.com> wrote:
>
>   
>> On 3/12/07, Chao Xu <dreamerx2004在gmail.com> wrote:
>>     
>>> 要是001呢?
>>>
>>>       
>> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
>>
>>     
>
> 他的意思可能是像密码锁那样的,三位数。。。。。每个都是从0-9
> 不是我们理解的数学上的三位数。。。。
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月13日 星期二 15:22

东子 hydonlee在gmail.com
星期二 三月 13 15:22:43 HKT 2007

可以结贴了. 多数人接受答案了.

在07-3-13,Gavin <gavin at sz.net.cn> 写道:
>
>
> '%03d'%random.randint(0,999)
>
>
> ----- Original Message -----
> 发件人: "amingsc" <amingsc at gmail.com>
> 收件人: <python-chinese at lists.python.cn>
> 发送时间: 2007年3月12日 14:37
> 主题: Re: [python-chinese] python怎么生成3位随机数?
>
>
> import random
> result = ''.join([str(random.randint(0,9)) for i in range(3)])
>
> Sean 写道:
> > On Mon, 12 Mar 2007 14:08:16 +0800, limodou <limodou at gmail.com> wrote:
> >
> >
> >> On 3/12/07, Chao Xu <dreamerx2004 at gmail.com> wrote:
> >>
> >>> 要是001呢?
> >>>
> >>>
> >> 001不就是1吗?能算是3位整数吗?别和字符串混了吧。
> >>
> >>
> >
> > 他的意思可能是像密码锁那样的,三位数。。。。。每个都是从0-9
> > 不是我们理解的数学上的三位数。。。。
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
只要人间真情在, 何必在意路泥泞
时风日下,和谐需要靠暴力达到!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070313/98bacc61/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号