Spaces:
Running
Running
Maybe random generator fixed
Browse files
script.js
CHANGED
@@ -7,24 +7,27 @@ async function fetchRestaurants() {
|
|
7 |
return data;
|
8 |
}
|
9 |
|
10 |
-
function
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
}
|
19 |
-
|
|
|
|
|
|
|
20 |
}
|
21 |
|
22 |
async function displayRestaurants() {
|
23 |
const today = new Date();
|
24 |
const day = today.getDay();
|
25 |
-
const year = today.getFullYear();
|
26 |
-
const month = today.getMonth() + 1; // Months are zero-based
|
27 |
-
const date = today.getDate();
|
28 |
|
29 |
// Format the date
|
30 |
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
|
@@ -55,7 +58,8 @@ async function displayRestaurants() {
|
|
55 |
try {
|
56 |
const restaurants = await fetchRestaurants();
|
57 |
console.log('Fetched Restaurants:', restaurants); // Debugging: Print fetched restaurants
|
58 |
-
const
|
|
|
59 |
console.log('Random Restaurants:', randomRestaurants); // Debugging: Print random restaurants
|
60 |
document.getElementById('restaurants').innerHTML = randomRestaurants.map(restaurant =>
|
61 |
`<a href="${restaurant[1]}" target="_blank">${restaurant[0]}</a>`
|
|
|
7 |
return data;
|
8 |
}
|
9 |
|
10 |
+
function seededRandom(seed) {
|
11 |
+
var x = Math.sin(seed++) * 10000;
|
12 |
+
return x - Math.floor(x);
|
13 |
+
}
|
14 |
|
15 |
+
function getRandomRestaurants(restaurants, seed) {
|
16 |
+
// Generate three random indices based on the seed
|
17 |
+
const indices = [];
|
18 |
+
for (let i = 0; i < 3; i++) {
|
19 |
+
const randomIndex = Math.floor(seededRandom(seed + i) * restaurants.length);
|
20 |
+
indices.push(randomIndex);
|
21 |
}
|
22 |
+
|
23 |
+
// Get the corresponding restaurants
|
24 |
+
const randomRestaurants = indices.map(index => restaurants[index]);
|
25 |
+
return randomRestaurants;
|
26 |
}
|
27 |
|
28 |
async function displayRestaurants() {
|
29 |
const today = new Date();
|
30 |
const day = today.getDay();
|
|
|
|
|
|
|
31 |
|
32 |
// Format the date
|
33 |
const options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
|
|
|
58 |
try {
|
59 |
const restaurants = await fetchRestaurants();
|
60 |
console.log('Fetched Restaurants:', restaurants); // Debugging: Print fetched restaurants
|
61 |
+
const seed = today.getFullYear() * 10000 + (today.getMonth() + 1) * 100 + today.getDate(); // Create a seed from the date
|
62 |
+
const randomRestaurants = getRandomRestaurants(restaurants, seed);
|
63 |
console.log('Random Restaurants:', randomRestaurants); // Debugging: Print random restaurants
|
64 |
document.getElementById('restaurants').innerHTML = randomRestaurants.map(restaurant =>
|
65 |
`<a href="${restaurant[1]}" target="_blank">${restaurant[0]}</a>`
|