import random


def random_book(json_data):
    """
    selects a random book out of all books on a given user shelf via json_data
    :param json_data: json data provided by the Goodreads API for a given user shelf
    :return: string of a books title and author
    """
    total = json_data["GoodreadsResponse"]['reviews']["@total"]
    book_index = random.randint(1, int(total))

    title = json_data["GoodreadsResponse"]["reviews"]["review"][book_index]["book"]["title"]
    author = json_data["GoodreadsResponse"]["reviews"]["review"][book_index]["book"]["authors"]["author"]["name"]

    return f"{title} by {author}"