Skip to content

Commit

Permalink
Fix subscription randomisation in shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxocube committed Jan 4, 2025
1 parent 0e79abe commit e2fe01c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions MediaFeeder/MediaFeeder/Components/Pages/Shuffle.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ protected override async Task OnInitializedAsync()
if (FolderId != null)
_subscriptions = await DataContext.Subscriptions
.Where(s => s.ParentFolderId == FolderId)
.OrderBy(static s => Guid.NewGuid())
.ToListAsync();
else if (SubscriptionId != null)
_subscriptions = [await DataContext.Subscriptions.SingleAsync(s => s.Id == SubscriptionId)];
else
_subscriptions = await DataContext.Subscriptions
.OrderBy(static s => Guid.NewGuid())
.ToListAsync();

StateHasChanged();

// Shuffle the order of the subscriptions
var rng = new Random(unchecked(Environment.TickCount * 31 + Environment.CurrentManagedThreadId));

for (var i = 0; i < _subscriptions.Count; i++)
{
i--;
var k = rng.Next(i + 1);
(_subscriptions[k], _subscriptions[i]) = (_subscriptions[i], _subscriptions[k]);
}

_videos.Enqueue(
await DataContext.Videos
.Where(v => v.Watched == false && _subscriptions.Contains(v.Subscription))
Expand Down

0 comments on commit e2fe01c

Please sign in to comment.