...把数据放到一个数组或者 list 中, 然后用 random(可能写错了)得出五个不同的 integer 值,有相同的就再来一次random, 程序就不写了

解决方案 »

  1.   

    Math.random() 随机得到一个0到1的数,去取员工
    再判断一下这个员工是否中过奖,中了再重新来一遍
      

  2.   

    Math.random()
    就可以得到随机数了 
      

  3.   

    随机从某个表中取5条数据,其中表中的id随你的表的记录数而定,我现在测试用的是10000 
    create table #t( id int,name varchar(50))    
    declare @random_Id int    
    declare @Count int    
    declare @temp int  
      
        set @Count=1    
        while @Count<=5    
            begin    
                select @random_Id=cast(10000*rand() as int)    
                if (@random_Id!=0)    
                    set @temp=(select top 1 id from person_main where id =@random_Id and person.id not in (select id from #t))   
                    if(@temp is not null)   
                        begin   
                            insert into #t    
                            select top 1 id,name from person_main where id =@random_Id and person.id not in (select id from #t)    
                            set @Count=@Count+1    
                        end    
                           
                   
                       
            end    
        select * from #t   
      
    drop table #t  全sql方式
      

  4.   

    java.util.Random获取随机数.
    对于已经抽过的人
    要么给你的表上加一个state字段
    要么另外建一个表记录抽奖的记录.
    当然,如果是web程序,能保证一直正常运行,存到webapplication里也可以
    不过,为了保险起见,新建一个表来保存或者加个字段是比较好的选择.关注下面的朋友更好的方法
      

  5.   

    纯java方式
    Collections.shuffle(list)
    把一些员工放到list里面,shuffle下后,直接取前5个就ok,这个是纯java方式,原list把前5个remove掉,在来shuffle,在取前5个,如此往复
      

  6.   

    关注,同意楼上的观点,应该和java.util.random有关吧