Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _includes/design_help/provider.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="box bg-white shadow mb-30">
<div id="{{include.provider.slug}}" class="box bg-white shadow mb-30 provider-item">
<div class="row">
{% if include.provider.avatar %}
<div class="col-md-4">
Expand Down
107 changes: 103 additions & 4 deletions design-help.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
sub_title: "Get assistance with your GF180MCU chip designs"
header_image: "/assets/images/header/mpw-one-partial-dice-top-1.jpg"
---
<style>
#provider-list {
display: flex;
flex-direction: column;
}
</style>
{% include layouts/nav/nav.html drop_search=false alignment_class="ms-auto" %}
{% include layouts/header/page-title.html %}

Expand All @@ -16,11 +22,104 @@ <h3 class="section-title text-center mb-20">Professional Services</h3>
<br><small class="text-muted"><em>Note: These services are not affiliated with or endorsed by wafer.space.
Please contact them directly to discuss your project needs.</em></small>
</p>
<div class="sr-only" aria-live="polite">
Provider order is randomized for fairness. Visual order may differ from screen reader order.
</div>

<div id="provider-list">
{% assign professional_help = site.design_help | where: "category", "professional" %}
{% for provider in professional_help %}
{% include design_help/provider.html provider=provider %}
{% endfor %}
</div>

<script>
(function() {
'use strict';

// LCG (Linear Congruential Generator) parameters - MINSTD
var LCG_MODULUS = 2147483647; // 2^31 - 1 (Mersenne prime)
var LCG_MULTIPLIER = 16807;

// Seeded Random Number Generator (Linear Congruential Generator)
function SeededRandom(seed) {
this.seed = seed % LCG_MODULUS;
if (this.seed <= 0) this.seed += LCG_MODULUS - 1;
}

SeededRandom.prototype.next = function() {
this.seed = (this.seed * LCG_MULTIPLIER) % LCG_MODULUS;
return (this.seed - 1) / (LCG_MODULUS - 1);
};

// Fisher-Yates shuffle with seeded random
function shuffleArray(array, random) {
var shuffled = array.slice();
for (var i = shuffled.length - 1; i > 0; i--) {
var j = Math.floor(random.next() * (i + 1));
var temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled;
}

// Get or create seed from localStorage
var SEED_KEY = 'designHelpProviderSeed';
var seed;

try {
seed = localStorage.getItem(SEED_KEY);
if (!seed) {
seed = Math.floor(Math.random() * LCG_MODULUS);
localStorage.setItem(SEED_KEY, seed);
} else {
Comment thread
mithro marked this conversation as resolved.
seed = parseInt(seed, 10);
// Validate seed is a valid number in expected range
if (isNaN(seed) || seed <= 0 || seed >= LCG_MODULUS) {
seed = Math.floor(Math.random() * LCG_MODULUS);
localStorage.setItem(SEED_KEY, seed);
}
}
Comment thread
mithro marked this conversation as resolved.
} catch (e) {
// localStorage not available (private mode, etc.)
if (console && console.debug) {
console.debug('Failed to access localStorage for provider shuffle:', e);
}
seed = Math.floor(Math.random() * LCG_MODULUS);
}

// Get all provider items
var container = document.getElementById('provider-list');
if (!container) return;

var providers = container.querySelectorAll('.provider-item');
if (providers.length <= 1) return; // No need to shuffle if 0 or 1 items

// Create array of indices

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor optimization: Creating a separate indices array and then shuffling it adds an unnecessary step. You could simplify this by generating the shuffled order values directly or by using a different approach. However, the current code is clear and readable, so this is a nitpick rather than a critical issue. The performance impact with ~4 providers is negligible.

var indices = [];
for (var i = 0; i < providers.length; i++) {
indices.push(i);
}

// Shuffle indices using seeded random
var random = new SeededRandom(seed);
var shuffledIndices = shuffleArray(indices, random);

// Apply CSS order to each provider
for (var i = 0; i < providers.length; i++) {
providers[i].style.order = shuffledIndices[i];
Comment thread
mithro marked this conversation as resolved.
Comment thread
mithro marked this conversation as resolved.
}

{% assign professional_help = site.design_help | where: "category", "professional" %}
{% for provider in professional_help %}
{% include design_help/provider.html provider=provider %}
{% endfor %}
// Re-scroll to hash target if present (fixes race condition)
if (window.location.hash) {
var target = document.getElementById(window.location.hash.substring(1));
if (target) {
target.scrollIntoView();
}
}
})();
</script>
</div>
</div>

Expand Down
Loading