Repository: internetarchive/openlibrary

Issue:
https://openlibrary.org/random seems to have only two works available 
<!-- What problem are we solving? What does the experience look like today? What are the symptoms? -->
If someone goes to https://openlibrary.org/random repeatedly, the results will be one of two works. The two works seem to change over time.
### Evidence / Screenshot (if possible)

### Relevant url?
<!-- `https://openlibrary.org/...` -->
https://openlibrary.org/random
### Steps to Reproduce
<!-- What steps caused you to find the bug? -->
1. Go to ...https://openlibrary.org/random several times.
2. Do ...Note that you will only ever get one of the two same titles.

<!-- What actually happened after these steps? What did you expect to happen? -->
* Actual: See description above.
* Expected: Given all the works on Open Library, it seems a random selection will rarely repeat.

### Details

- **Logged in (Y/N)?**
- **Browser type/version?**
- **Operating system?**
- **Environment (prod/dev/local)?** prod
<!-- If not sure, put prod -->

### Proposal & Constraints
<!-- What is the proposed solution / implementation? Is there a precedent of this approach succeeding elsewhere? -->

### Related files
<!-- Files related to this issue; this is super useful for new contributors who might want to help! If you're not sure, leave this blank; a maintainer will add them. -->

### Stakeholders
<!-- @ tag stakeholders of this bug -->
@mekarpeles 


Discussion:

Resolving patch:
diff --git a/openlibrary/core/lending.py b/openlibrary/core/lending.py
--- a/openlibrary/core/lending.py
+++ b/openlibrary/core/lending.py
@@ -1,11 +1,12 @@
 """Module for providing core functionality of lending on Open Library.
 """
-from typing import Literal, Optional, List
+from typing import Literal, Optional
 
 import web
 import datetime
-import time
 import logging
+import random
+import time
 import uuid
 
 import eventer
@@ -207,21 +208,22 @@ def compose_ia_url(
     return base_url + '?' + urlencode(params)
 
 
-def get_random_available_ia_edition():
+def get_random_available_ia_edition() -> str:
     """uses archive advancedsearch to raise a random book"""
     try:
         url = (
             "http://%s/advancedsearch.php?q=_exists_:openlibrary_work"
-            "+AND+(lending___available_to_borrow:true OR lending___available_to_browse:true)"
+            "+AND+(lending___available_to_borrow:true"
+            " OR lending___available_to_browse:true)"
             "&fl=identifier,openlibrary_edition"
-            "&output=json&rows=1&sort[]=random" % (config_bookreader_host)
-        )
+            "&output=json&rows=25&sort[]=random" % (config_bookreader_host)
+        )  # internetarchive/openlibrary#6592: Request 25 editions and randomly choose
         response = requests.get(url, timeout=config_http_request_timeout)
         items = response.json().get('response', {}).get('docs', [])
-        return items[0]["openlibrary_edition"]
+        return random.choice(items)["openlibrary_edition"]
     except Exception:  # TODO: Narrow exception scope
-        logger.exception("get_random_available_ia_edition(%s)" % url)
-        return None
+        logger.exception(f"get_random_available_ia_edition({url})")
+        return ''
 
 
 @public


Test patch: