我試圖想出一個隨機數發生器,它返回一個介於0和1之間的浮點值,並在一個方向或另一個方向上返回值。隨機數字發生器,它將數字吸引到範圍內的任何給定數字?
是否有任何可靠的方法來做到這一點,基於傳入兩個數字,例如隨機(0.5)其中'0.5'表示返回0和1之間的數字將傾向於0.5。
我試圖想出一個隨機數發生器,它返回一個介於0和1之間的浮點值,並在一個方向或另一個方向上返回值。隨機數字發生器,它將數字吸引到範圍內的任何給定數字?
是否有任何可靠的方法來做到這一點,基於傳入兩個數字,例如隨機(0.5)其中'0.5'表示返回0和1之間的數字將傾向於0.5。
這可能有幫助嗎?
它不會精確地解決您的問題,但我想知道,如果模擬鐘形曲線可能會提供你正在尋找的傾向。
雖然有趣的問題,我可以問你想要解決什麼?
第二編輯:我只注意到另一個S/O的問題,這可能有助於:
我正在做一個遊戲(http: //jabberworx.net/meteormania/meteormania.html),它創造了不同大小的流星。我想讓它繼續產生隨機的流星,但我想要比大流星更多的小流星,但仍然保持隨機.. – tweetypi 2011-04-28 10:45:37
這很酷,祝你好運! – 2011-04-28 11:29:09
什麼你指的是投射到一個鐘形曲線的隨機數
對此我一般請執行以下操作
/// <summary>
/// generate a random number where the likelihood of a large number is greater than the likelihood of a small number
/// </summary>
/// <param name="rnd">the random number generator used to spawn the number</param>
/// <returns>the random number</returns>
public static double InverseBellCurve(Random rnd)
{
return 1 - BellCurve(rnd);
}
/// <summary>
/// generate a random number where the likelihood of a small number is greater than the likelihood of a Large number
/// </summary>
/// <param name="rnd">the random number generator used to spawn the number</param>
/// <returns>the random number</returns>
public static double BellCurve(Random rnd)
{
return Math.Pow(2 * rnd.NextDouble() - 1, 2);
}
/// <summary>
/// generate a random number where the likelihood of a mid range number is greater than the likelihood of a Large or small number
/// </summary>
/// <param name="rnd">the random number generator used to spawn the number</param>
/// <returns>the random number</returns>
public static double HorizontalBellCurve(Random rnd)
{
//This is not a real bell curve as using the cube of the value but approximates the result set
return (Math.Pow(2 * rnd.NextDouble() - 1, 3)/2)+.5;
}
請注意,您可以調整公式以更改鈴聲的形狀以調整distributi結果
對於一個簡單的Math.Sqrt(rnd.nextdouble())將傾斜所有數字朝向1, 和一個簡單的Math.Power(rnd.nextdouble(),2)將傾斜結果朝向0
如果它傾向於它不隨機的東西。 – PVitt 2011-04-28 10:13:49
您可能需要更多有關您的問題的信息才能找到一個好的解決方案。你說「傾向於」。多快?多少?你在尋找正常/高斯分佈嗎? http://en.wikipedia.org/wiki/Normal_distribution – 2011-04-28 10:14:17
不,這將是一個非均勻的隨機數發生器 – 2011-04-28 10:14:26