用于模拟短信群发情况的随机数产生

短信下发时的一些条件
每分钟最高发送量,每分钟最高发送量,每分钟标准发送量,发送总量,
最后在产生每分钟发送量的随机数时还加上了一个波幅值来控制随机数偏向标准量的波动,这样可以模拟出网路情况好和不好时的不同状态。

下面是随机数序列产生的类
None.gif public   class  dataclass
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    Random rand 
= new Random();
InBlock.gif    
//生成随机数;
InBlock.gif
    private int getrand(int min,int max)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
int temprand = rand.Next(min, max);
InBlock.gif        
return temprand;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
//生成带最大最小偏向和波幅的随机数
InBlock.gif
    private int getformatrand(int min, int max, int def,int wav)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
int[,] temprand = new int[wav, 2];
InBlock.gif        
InBlock.gif        
for (int i = 0; i < wav; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            temprand[i, 
0= getrand(min, max);
InBlock.gif            temprand[i, 
1= (int)Math.Abs(temprand[i, 0- def);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
int temp = 0;
InBlock.gif        
for (int j = 0; j < wav - 1; j++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
for (int i = 0; i < wav - 1; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                temp 
= 0;
InBlock.gif                
if (temprand[i, 1> temprand[i + 11])
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    temp 
= temprand[i, 1];
InBlock.gif                    temprand[i, 
1= temprand[i + 11];
InBlock.gif                    temprand[i 
+ 11= temp;
InBlock.gif                    temp 
= temprand[i, 0];
InBlock.gif                    temprand[i, 
0= temprand[i + 10];
InBlock.gif                    temprand[i 
+ 10= temp;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return temprand[00];
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// 生成发送数据
InBlock.gif    
/// </summary>
InBlock.gif    
/// <param name="min">单位时间内最小发送量</param>
InBlock.gif    
/// <param name="max">单位时间内最大发送量</param>
InBlock.gif    
/// <param name="def">单位时间内标准发送量</param>
InBlock.gif    
/// <param name="wav">波幅,1波动最大,数字或大波动越小</param>
InBlock.gif    
/// <param name="num">发送总量</param>
ExpandedSubBlockEnd.gif    
/// <returns></returns>

InBlock.gif    public string[] getsendnum(int min, int max, int def, int wav, int num)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
string temp = "";
InBlock.gif        
InBlock.gif        
for (int i = 0; i < num; )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
int temprand = getformatrand(min, max, def, wav);
InBlock.gif
InBlock.gif            
if ((i + temprand) >= num)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                temprand 
= num - i;
InBlock.gif                i 
+= temprand;
InBlock.gif                temp 
+= temprand;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                i 
+= temprand;
InBlock.gif                temp 
+= temprand + ",";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
string[] str = temp.Split(new char[]dot.gif{','});
InBlock.gif        
return str;
InBlock.gif        
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

产生的是一组字符串数组,但都是数字,必要时可以转成整型应用就是了。

下面给两个演示图,主要是看波幅的控制
波幅为5时的情况
bf5.JPG
再来个波幅为50时的情况图
bf50.JPG
可以看到随机数产生的波动效果了吧。

其实思想很简单,在范围内产生的随机数的波动是控制不了的,那么怎么控制它偏向某个值呢?很简单,取多个随机数,从中找出离标准值最近的,也就是用它减标准值后,绝对值最小的那个,那么其它不要了,就取这个就行了,这样产生的一系列随机数就会向标准值偏向,每次产生的越多,最终得出的数值就离标准值越近,所以我这里这个波幅值(网络环境)其实就是定义的随机数每次产生的个数,在多少个中选一,当然数字越大,波幅越小了,哈哈!

这是一个小项目里用到的,接下来我要做的就是把生成的这组数据转成曲线图,对客户来说就看到一个比较完美的模拟了。

转载于:https://www.cnblogs.com/aowind/archive/2006/11/08/554185.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值