我写的循环 但需要得到符合要求的随机数 高手看看怎么补
declare @inti int,
@namelength int ,
@strNew char (100),
@strA char (40)
select @inti = 0,
@strA = '0123456789abcdefghigklmnopqrstuvwxyz',
@namelength = rand ()-- 需要一个1--100的随机数 做为name的长度
while (@inti < @namelength)
begin
set @strNew ='"+ @strNew + substring(@strA, rand (),1)+ "' -- 在侯选的36个字符中随机截取一个字符,需要<=36的随机数
set @inti =@inti +1
end
还望高手指教啊
declare @inti int,
@namelength int ,
@strNew char (100),
@strA char (40)
select @inti = 0,
@strA = '0123456789abcdefghigklmnopqrstuvwxyz',
@namelength = rand ()-- 需要一个1--100的随机数 做为name的长度
while (@inti < @namelength)
begin
set @strNew ='"+ @strNew + substring(@strA, rand (),1)+ "' -- 在侯选的36个字符中随机截取一个字符,需要<=36的随机数
set @inti =@inti +1
end
还望高手指教啊
@namelength int ,
@strNew char (100),
@strA char (40)
select @inti = 0,
@strA = '0123456789abcdefghigklmnopqrstuvwxyz',
@namelength = ceiling(rand(-1) * 100)-- 需要一个1--100的随机数 做为name的长度
while (@inti < @namelength)
begin
set @strNew ='"+ @strNew + substring(@strA, ceiling(rand(@inti) * 36),1)+ "' -- 在侯选的36个字符中随机截取一个字符,需要<=36的随机数
set @inti =@inti +1
end----------------------------------------------------------------------
RAND
返回 0 到1 之间的随机float 值。语法
RAND ( [ seed ] ) 参数
seed是给出种子值或起始值的整型表达式(tinyint、smallint 或 int)。返回类型
float注释
在单个查询中反复调用 RAND() 将产生相同的值。 ---------------注意这个
但这种方法在一个较短内容易产生一样的数 特别是在循环中
seed是给出种子值或起始值的整型表达式(tinyint、smallint 或 int)。
---------------------------------------------------------------
@namelength = replace(ceiling(rand()*100),'.0','')
@namelength = replace(ceiling(rand()*100),'.0','')是对的 不用乘以101
谢谢各位的热心了