python,c++,C#Ëæ»úÊýÉú³É
ÏÈ˵python
pythonµÄrandomÄ£¿éÌṩÁ˶à¸öαËæ»úÊý·¢ÉúÆ÷£¬Ä¬È϶¼ÊÇÓõ±Ç°Ê±¼ä´ÁΪËæ»úÊýÖÖ×Ó¡£
ÏÂÃæÊǸÃÄ£¿é¼¸¸ö×î³£Óõĺ¯Êý
random() Return the next random floating point number in the range [0.0, 1.0).
randint(a,b) Return a random integer N such that a <=
N <= b
randrange([start,]stop[,step]) Return a randomly selected element from range(start,
stop, step).
sample(seq,k) Return k length list of unique elements chosen from the sequence seq(´ÓÐòÁÐÖÐÈ¡³ök¸ö²»Öظ´µÄÖµ£¬ÓÃÆðÀ´·½±ã)
uniform(a,b) Return a random real number N such that a<=N<b
choice(seq) Return a random element from the NONE-empty sequence seq,if seq is empty,raises indexerror
seed([x]) ÉèÖÃËæ»úÊý·¢ÉúÆ÷µÄÖÖ×ÓÖµ£¬Ä¬ÈÏÒÔϵͳʱ¼äΪÖÖ×Ó£¬¾«¶ÈÓ¦¸ÃºÜ¸ß¡£
mark:pythonµÄrandomÄ£¿é»¹ÌṩÁ˸ß˹·Ö²¼£¬ÕýÌ«·Ö²¼£¬beta·Ö²¼µÈµÄËæ»úÊýÉú³É¡£
import random
random.random()
random.randint(0, 1)
random.choice('abcdefghij')
random.uniform(1, 3)
random.sample([1, 2, 3, 4, 5, 6, 7, 8, 9], 5)
ÆäÖУ¬random.randomµÄЧÂÊÒª±Èrandom.int¿ì70±¶¡£
C++µÄËæ»úÊý
rand()ºÍsrand(unsigned int seed)
C++±ê×¼º¯Êý¿âÌṩһËæ»úÊýÉú³ÉÆ÷rand£¬·µ»Ø0£RAND_MAXÖ®¼ä¾ùÔÈ·Ö²¼µÄαËæ»úÕûÊý¡£ RAND_MAXΪ32767¡£rand()º¯Êý²»½ÓÊܲÎÊý£¬Ä¬ÈÏÒÔ1ΪÖÖ×Ó£¨¼´Æðʼֵ£©¡£ Ëæ»úÊýÉú³ÉÆ÷×ÜÊÇÒÔÏàͬµÄÖÖ×Ó¿ªÊ¼£¬ËùÒÔÐγɵÄαËæ»úÊýÁÐÒ²Ïàͬ£¬Ê§È¥ÁËËæ»úÒâÒå¡££¨µ«ÕâÑù±ãÓÚ³ÌÐòµ÷ÊÔ£©
C++ÖÐÁíÒ»º¯Êýsrand£¨£©£¬¿ÉÒÔÖ¸¶¨²»Í¬µÄÊý£¨ÎÞ·ûºÅÕûÊý±äÔª£©ÎªÖÖ×Ó¡£µ«ÊÇÈç¹ûÖÖ×ÓÏàͬ£¬Î±Ëæ»úÊýÁÐÒ²Ïàͬ¡£Ò»°ãÊÇÓõ±Ç°Ê±¼ä×÷ΪÖÖ×Ó
ÓÃtime£¨null£©£¬Òª°üº¬time.hÍ·Îļþ
srand((unsigned)time(null))
rand()%MAX
ҪʵÏÖÉÏÃæpythonÆäËû¸÷ÖÖ¹¦ÄÜÖ»ÄÜ×Ô¼ºÊµÏÖÁË¡£
²¢ÇÒÓÉÓÚrandĬÈÏÊÇÒÔ1ΪÖÖ×Ó£¬ËùÒÔÒªÉú³ÉËæ»úÊýʱһ¶¨ÒªÉèÖÃÖÖ×ÓµÄÖµ...
C#µÄËæ»úÊý
RandomÀà
Random ro=new Random() ĬÈÏÒÔµ±Ç°ÏµÍ³Ê±¼ä×÷ΪÖÖ×Ó
ro.Next([a,]b) ·µ»ØÒ»¸ö£¨´óÓÚµÈÓÚa£©Ð¡ÓÚbµÄ·Ç¸ºËæ»úÊý
ro.NextDouble() ·µ»ØÒ»¸ö½éÓÚ0.0ºÍ1.0Ö®¼äµÄËæ»úÊý
ÖµµÃ×¢ÒâµÄÊÇ£¬ÓÉÓÚϵͳʱ¼äµÄ·Ö±æÂÊÓÐÏÞ£¬¶ÔÓÚc++ºÍC#£¬Ê¹ÓÃϵͳʱ¼äÒ²Ö»ÊǾ«È·µ½Ã루pythonµÄ¾«¶ÈºÜ¸ß£©£¬Èç¹ûÁ½´ÎÉèÖÃÖÖ×ÓµÄʱ¼äСÓÚ1Ã룬ÄÇôµÃµ½µÄÐòÁоÍÊÇÒ
Ïà¹ØÎĵµ£º
http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html
Sunday, May 10, 2009
Hadoop should target C++/LLVM, not Java (because of watts)
< type="text/javascript">
digg_url="http://www.trendcaller.com/2009/05/hadoop-should-target-cllvm-not-java.html";
Over the years, ......
2010-03-16
1£¬×Ö·û´®³£Á¿£º¾ÍÊÇÔÚÔ´³ÌÐòÖб»Ë«ÒýºÅÀ¨ÆðÀ´µÄÒ»´®×Ö·û£¬ÀýÈç“hello”¡£ÔÚÄÚ´æÖдæ6¸ö×Ö½Ú£¬°üÀ¨×îºóÒ»¸öNUL×Ö½Ú£¨¼´‘\0’£©.
2£¬NULÊÇASCii×Ö·û¼¯ÖБ\0’×Ö·ûµÄÃû×Ö£¬ËüµÄ×Ö½ÚģʽΪȫ0. NULLÖ¸Ò»¸öÆäֵΪ0µÄÖ¸Õ룬ËûÃǶ¼ÊÇÕûÐÍÖµ£¬ÇÒÖµ¶¼Ïàͬ£¬ËùÒÔËûÃÇ¿ÉÒÔ»¥»»Ê¹Ó㬵« ......
Ò»¡¢¸ÅÊö
1¡¢C++ËäÈ»ÊÇ´ÓCÓïÑÔÖз¢Õ¹µÄ£¬µ«ÆäÖÐÓÐÐí¶àÒªµã£¬ÊÇCÓïÑÔÖÐËùûÓеģ¬°üÀ¨ÒýÓã¬ÄÚÁªº¯ÊýµÈ£¬ÔÚ´Ë×öÒ»¸ö½éÉÜ¡£
2¡¢¶ÔÓÚC/C++ÖеĻù´¡ÊDZØÐëÒªÏêϸÁ˽âµÄ£¬Äܹ»Éî¿ÌÀí½âÆ京ÒåÒÔ¼°ÆäÀ´Ô´£¬ÊÇÒ»¸öÈËÄÚ¹¦Éî¿ÌµÄ±íÏÖ¡£Èç¹ûһЩ»ù´¡µÄÎÊÌ⣬
¶¼Ëµ²»ÉÏÀ´£¬ÓÖÈçºÎ¸øÈËÒÔÐÅÐÄÄØ¡£
¶þ¡¢³£¼ûµÄÎÊÌâ
1¡¢ÎªÊ²Ã´ÒªÊ¹ ......
#ðÅÝÅÅÐò
def BubbleSort(mylist):
n = len(mylist)
i = 0
j = 0
bExchange = False
for i in range(1, n):
bExchange = False
j = n - 1
while j >= i:
if mylist[j] < mylist[j - 1]:
tmp = mylist[j]
myli ......
#¶ÑÅÅÐò
def Heapify(mylist, start, end):
left = 0
right = 0
maxv = 0
left = start * 2
right = start * 2 + 1
while left <= end:
maxv = left
if right <= end:
if mylist[left] < mylist[right]:
maxv = right
......