重构 一个大乐透选彩票的

yeyong14 · 2013年03月26日 · 最后由 aa1122 回复于 2020年04月22日 · 2385 次阅读

今天妈妈排了几个小时的队,终于冲了 500 元燃气费,因为听说燃气要涨价了。好多人都在赶着冲钱。我感觉生活的成本现在真是越来越高的,在魔都靠这点工资很难活着。就想着一夜暴富,想着买几注彩票。参考一下别人的,自己也动手做了一个,随机买了几注,希望有好运。

这样写的总感觉很粗糙的,总觉的有很大的重构的空间,因最近新进 Ruby,我不知道怎么修改,希望得到大家的帮助,最好能在加进去些算法。

daletou = proc {
  @luck = []
    while @luck.size < 5
      fiveball = rand(35) + 1
      @luck << fiveball unless @luck.include?(fiveball)
      end
      @luck.sort!

      def blueball
        @lucktwo = []
         while @lucktwo.size < 2
          ball = rand(15) + 1
          @lucktwo << ball unless @lucktwo.include?(ball)
          end
          @lucktwo.sort!
       end

       @luck << blueball

       p @luck
}
3.times { daletou.call }

用算法还不如直接上 hadoop 分析历期开奖号码,再说这玩意你相信有算法??

#encoding: utf-8

class ShuangSeQiu
  def initialize
    @times = ARGV && ARGV[0] ? ARGV[0].to_i : 5
  end

  def create
    @times.times do |time|
      reds = []
      base_rads = Array.new(36) {|i| i + 1}
      6.times do |r|
        length = base_rads.length
        reds << base_rads.delete_at(Random.rand(0..length - 1))
      end
      puts "red number are #{reds.sort.join(', ')}"
      puts "blue number is #{Random.rand(1..16)}"
      puts '='*80
    end
  end

end

ShuangSeQiu.new.create

随便写个 random 出来行了

獨立事件獨立概率.... 純 random 即可

算了,我还是相信彩票自己的随机算法!

彩票这东西 有规则 没规律。

照着规则走~ 我之前试过用 R 去算过一次~ 但得到的结果是需要大量的资金 呵呵 这个东西玩玩就好了 就好比每个学化学的家伙 总梦想着能点石成金一样。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号