jeudi 17 mai 2018

How do I write a program that generates a random number and then generates another random number with certain margins based on the first number?

I'm a noob so it's likely that I'm not explaining it very well, especially in the title.

I start with rand(1..117). Let's say it prints 80. Now I want to add another part that generates another random number between 20 less and 20 more than the first number, but still between 1 and 117.

I want a sequence of this that generates about a 100 numbers with the same margins, from second to last based on the previously generated number.

Would really appreciate some help. if you know of a way the same program can be written faster in a language other than Ruby, I'd like to know which one and how - though I mostly want to know for Ruby.




Aucun commentaire:

Enregistrer un commentaire