Feedback Random Quote Machine

Hi all,

I have just finished my exercise and I would like to get some feedback if is possible. I have done it trying to copy the design from the original.

I am not sure if the algorithm I am using to generate a random phrase is the right one. I have just seen some on the Internet that I really like , but I haven’t used any of them because I wanted to try to do it on my own.

My Algorithm generates en index and if it is repeated, generates it again until it gets a no-repeat one. For that I store all the indices in an array. But I am afraid if the list of phrases is very big, then my algorithm can be slow.

My code is here:

Thank you in advance!!

It’s true that if the list of indices were very large, you might see some performance hit when the app traverses the array, but it would take you years to hard code enough quotes for that to matter. Algorithms don’t always have to scale, and yours works just fine for the purpose of your app. Besides, if you had enough quotes to matter, you probably wouldn’t need the algorithm to prevent repeats because they would be statistically unlikely.

It looks really good!

1 Like

Thank you,
But I am worried now about not doing what the exercise demanded because I haven’t used an API. I created the JSON array on my own. And I developed the random algorithm but the porpouse of the exercise was to use one of the API’s handable on the internet.

Do you know any random quote API?? in most of them you have to either register or pay, and I am looking for some for free.

Thank you in advance!!

It just so happens I answered the very question recently!


Don’t stress too much over what you should or shouldn’t have done. Learn what you can. Just because a project is “done” doesn’t mean you can’t ever touch it again.

1 Like