Functions.CharMix 方法 |
命名空间: XSharp.Core
1? CharMix("13579", "24680") // 1234567890
1Function Start() 2 LOCAL cPoker AS STRING 3 cPoker := "AKJQ0123456789" 4 ? Shuffle(cPoker, 10) // Q37A048K159J26 5 RETURN TRUE 6FUNCTION Shuffle(cDeck AS STRING, ; 7 siShuffles AS SHORTINT) AS STRING PASCAL 8 // 假设卡片数量为偶数。 9 // cDeck的长度可被2整除 10 LOCAL siCounter AS SHORTINT 11 LOCAL siCards AS SHORTINT 12 siCards := SLen(cDeck) 13 // 第一张和最后一张牌不洗牌; 14 // 所以添加/填充空白卡 15 siCards += 2 16 cDeck := PadC(cDeck, siCards) 17 FOR siCounter := 1 UPTO siShuffles 18 // 将牌组切成两半并洗牌 19 cDeck := CharMix(Substr3(cDeck, 1,; 20 siCards/2), Substr2(cDeck, (siCards/2)+1)) 21 NEXT 22 RETURN Substr3(cDeck, 2, siCards-2) 23 // 排除添加的空白卡