⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 04 - generating random numbers.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
rand    # => 0.517297883846589rand    # => 0.946962603814814#---rand(5)            # => 0rand(5)            # => 4rand(5)            # => 3rand(1000)         # => 39#---a = ['item1', 'item2', 'item3']a[rand(a.size)]                     # => "item3"#---m = { :key1 => 'value1',      :key2 => 'value2',      :key3 => 'value3' }values = m.valuesvalues[rand(values.size)]            # => "value1"#---def random_word letters = { ?v => 'aeiou',             ?c => 'bcdfghjklmnprstvwyz' }  word = ''  'cvcvcvc'.each_byte do |x|    source = letters[x]    word << source[rand(source.length)].chr  end  return wordendrandom_word                         # => "josuyip"random_word                         # => "haramic"#---#Some random numbers based on process number and current timerand(1000)                         # => 187rand(1000)                         # => 551rand(1000)                         # => 911#Start the seed with the number 1srand 1rand(1000)                         # => 37rand(1000)                         # => 235rand(1000)                         # => 908#Reset the seed to its previous statesrand 1rand(1000)                         # => 37rand(1000)                         # => 235rand(1000)                         # => 908#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -