Javascript 从unsplash API reactjs中选择一个随机图像

Javascript 从unsplash API reactjs中选择一个随机图像,javascript,reactjs,api,random,Javascript,Reactjs,Api,Random,我正在开发一个reactjs应用程序,它使用unsplash API更新应用程序的背景图像。API的结果如下所示: {total: 2330, total_pages: 78, results: Array(30)} 由于API每页仅返回30个图像,因此我实现了以下逻辑来从30个图像列表中检索任意图像: if (typeof response.data !== "undefined") { const num = Math.floor(Math.random

我正在开发一个reactjs应用程序,它使用unsplash API更新应用程序的背景图像。API的结果如下所示:

{total: 2330, total_pages: 78, results: Array(30)}
由于API每页仅返回30个图像,因此我实现了以下逻辑来从30个图像列表中检索任意图像:

        if (typeof response.data !== "undefined") {
          const num = Math.floor(Math.random() * 30) + 1;
          const url = response.data.results[num].urls.regular;
          updateBackground(url);
        }
但上述逻辑仅限于从第一页拾取随机图像。如何从总共2330张图像中随机选取一张图像?有没有办法从结果中排除总页面数


谢谢

随机照片API不是您需要的解决方案吗


否则,如果这不是您所需要的,您可以将您从中选择的页面随机添加到该页面内的照片中。

是的,有意义,我修改了api调用以获得如下随机图像:{location}&client_id=AAA谢谢