Created
February 12, 2024 09:22
-
-
Save Kuniwak/a2cada0949e17d3a006f6994c3c70667 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://chat.openai.com/share/a75ee402-3131-4ee8-9a9d-54bf1b81071c | |
using System; | |
namespace Playground.CopilotTDD.Tests | |
{ | |
public static class NumberGenerator | |
{ | |
public static int GetBetween0To100BySeed(int seed) | |
{ | |
// 線形合同法のパラメータ | |
const int a = 1103515245; | |
const int c = 12345; | |
const long m = (1L << 31); | |
// 線形合同法による疑似乱数生成 | |
long nextSeed = (a * seed + c) % m; | |
int randomNumber = (int)(nextSeed % 100); | |
// 特定の条件下で最頻値を 50 に調整 | |
if (randomNumber == 50 && seed % 2 == 0) | |
{ | |
return 50; | |
} | |
else if (randomNumber < 50) | |
{ | |
return randomNumber + 1; | |
} | |
else | |
{ | |
return randomNumber; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment