一定概率选中某一个字母怎么实现 ?

http://topic.csdn.net/u/20110409/13/7afe9821-e616-4154-82ff-fa70a5be8a9d_2.html?seed=1477573484&r=72683751#r_72683751

 

在C#版看到这一篇文章,手边现在正开著MacBook上网

实在不太想重新开Windows跟Visual Studio来编码

正好我也在练习C++ Template,那就很刚好试著用Template来实践一下

 

// // main.cpp // RandomTest // // Created by Cloud on 2011/4/10. // Copyright 2011年 Orz. All rights reserved. // #include #include using namespace std; template class RandomWord { T m_Word; int m_Probability; public: RandomWord(T word, int probability):m_Word(word),m_Probability(probability){} T getWord() { return m_Word; } int getProbability() { return m_Probability; } }; template class RandManager { vector > m_randomList; int m_sumOfProbability; public: RandManager() :m_randomList(), m_sumOfProbability(0) { } void AddRandomWord(RandomWord word) { if(m_sumOfProbability <= 100) m_randomList.push_back(word); cout<<"Add word:"< orz = m_randomList[i]; if( (sum <= randNum) && (randNum < (orz.getProbability() + sum))) { cout<<"Generate:"< manager; manager.AddRandomWord(RandomWord('A',10)); manager.AddRandomWord(RandomWord('B',10)); manager.AddRandomWord(RandomWord('C',35)); manager.AddRandomWord(RandomWord('D',25)); manager.AddRandomWord(RandomWord('E',20)); srand(time(NULL)); manager.RandomGenerate(rand()%100); return 0; }

你可能感兴趣的:(C/C++,manager,windows,c#,null,c)