In this tutorial we will generate groups of letters, numbers, and both! The ability to copy groups of letters and numbers is essential for copying callsigns well - especially during CW contests!
Four groups of random letters
We can generate words containing random letters by calling random_letters. We can also indicate the size and quantity of words required by passing random_letters the parameters as shown below:
# :size is size of group
# :count is number of groups to generate
random_letters(:size => 5, :count => 4)
The words produced can then be filtered further in the normal way.
# letter_number_groups.rb
require 'cw'
cw do
name " 4 letter groups, of 8 characters (15 wpm)"
random_letters(:count => 4, :size => 8)
wpm 15
test_letters
end
Four groups of random numbers
The random_numbers command works in a similar manner to random_letters
# letter_number_groups_2.rb
require 'cw'
cw do
name " 4 number groups, 6 characters (15 wpm)"
random_numbers(:count => 4, :size => 6)
wpm 15
test_letters
end
Four groups of mixed letters and numbers
There is also a command called random_alphanumeric which will generate groups of mixed numbers and letters. random_letters_numbers is an alias for random_alphanumeric and may be used if preferred.
# letter_number_groups_3.rb
require 'cw'
cw do
name " 4 groups of mixed letters and numbers with a size of 6 characters (12 wpm)"
random_letters_numbers(:count => 4, :size => 6)
wpm 12
test_letters
end
Using Ruby to generate more complex groupings
Since a cw-script is written in the Ruby language, we may utilize the power of Ruby within our tests to create groupings as complex as we like.
Below is an example of generating eight groups consisting of:
- four letter groups, each containing a letter ‘h’
- four number groups, each containing a number ‘5’
- the resulting eight groups are then shuffled
Note: This test introduces the command print_words, which prints the current letter just after it has been played by the audio player. It was introduced to practice code recognition (with no typing), typically at faster
speeds.
# letter_number_groups_4.rb
require 'cw'
cw do
name " 4 number groups, 6 characters (30 wpm)"
random_numbers(:size => 5)
words_including('5')
word_count 4
temp = words()
random_letters(:size => 5)
words_including('h')
word_count 4
self.words += temp
shuffle
wpm 30
print_letters
end