# Generate random words

**URL:** <https://forum.arduino.cc/t/generate-random-words/598589>\
**Category:** General Guidance\
**Created:** [June 24, 2019, 5:08pm UTC](https://forum.arduino.cc/t/generate-random-words/598589 "2019-06-24T17:08:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sabths](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sabths/32/236819_2.png) [@Sabths](https://forum.arduino.cc/u/Sabths)\
**Post date:** [June 24, 2019, 5:08pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/1 "2019-06-24T17:08:16Z")

</div>

Hi,

I'm new programming in arduino, and I'm trying to make a program that generates a thousand random words and then  
print them in serial, how could generate a thousand random words ?.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 24, 2019, 5:17pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/2 "2019-06-24T17:17:44Z")

</div>

> Sabths:  
> Hi,
> 
> I'm new programming in arduino, and I'm trying to make a program that generates a thousand random words and then  
> print them in serial, how could generate a thousand random words ?.
> 
> Regards.

1. You would need a source of words that you can randomize.
2. You need to know how many words you have.
3. You need to understand how to use random number [Arduino - Random Numbers](https://www.tutorialspoint.com/arduino/arduino_random_numbers.htm)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 24, 2019, 5:22pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/3 "2019-06-24T17:22:04Z")

</div>

Do they need to be real (ie from a dictionary) words, or random selections of letters?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 24, 2019, 5:33pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/4 "2019-06-24T17:33:04Z")

</div>

There may be some details online of the algorithm used in the game Elite to generate random words

---

<div class="post-metadata">

**Author:** ![DVDdoug](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dvddoug/32/671533_2.png) [@DVDdoug](https://forum.arduino.cc/u/DVDdoug)\
**Post date:** [June 24, 2019, 5:47pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/5 "2019-06-24T17:47:12Z")

</div>

You may need more memory, especially if there are more than 1000 words to choose from...

And, that's a LOT of "typing" to create that list within your code!

> that generates a thousand random words

I assume these are real words that you can find in the dictionary, not just random letters and made-up "words"? You can't "generate" real words without also generating lots of garbage.

It's easier if you want to generate garbage-nonsense "words". The [**[u]ASCII[/u]**](http://www.asciitable.com/) characters are from a=97 to z=122 (decimal), so all you have to do is generate random length strings (within whatever length constraints you want) of random chars between 97 and 122.

You can use an array of strings (one word per string) (or a [**[u]vector[/u]**](http://www.cplusplus.com/reference/vector/vector/) of strings).

Then, you can **randomly select the array pointer** (which is a "number").

If you want to make it impossible to select the same word twice, there are algorithms for "random selection without replacement". I forgot how these algorithms work, but one way to do it is to delete the word from the array (or vector), shifting-up everything below it and updating the number of items in the array.

---

<div class="post-metadata">

**Author:** ![ScrewLoose](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@ScrewLoose](https://forum.arduino.cc/u/ScrewLoose)\
**Post date:** [June 24, 2019, 6:01pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/6 "2019-06-24T18:01:56Z")

</div>

> AWOL:  
> There may be some details online of the algorithm used in the game Elite to generate random words

You made me squirm there. I was all hands up in the air, back at school going 'Please Miss I know that I know that' 🙂

A small bit of research and memory prodding and it all comes back to me - Francis Spufford wrote the book “Backroom Boys” which describes the development of the Elite game.

[quote author=Mr Spufford]  
They could encode all the information on a particular solar system in a relatively short row of digits. That number, it occurred to them, wouldn’t have to be stored if it were an iteration in a Fibonacci sequence – or a Fibonacci-like sequence, anyway. All you would need would be a starting point, a rule for doing the iterations, and a mechanism for extracting the information from the number.[/quote]

I remember reading that book some 25 years ago - great stuff. Thanks for bringing that all back to me.

1.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 6:57pm UTC](https://forum.arduino.cc/t/generate-random-words/598589/7 "2021-05-05T18:57:26Z")

</div>

Closed on May 5, 2021, 6:57pm UTC


