每當我的應用程序選擇一個「隨機」卡,它總是遵循相同的奇怪模式:俱樂部只有1-3,鑽石4-6,心臟7-9,黑桃10 -12。西裝永遠在這個數字範圍內,永不改變。每個套房應該被允許去13!請幫我解決令人困惑的問題,謝謝!Random.Next不會達到最大參數
來源:
Random Suite = new Random();
Random Value = new Random();
int sprod;
int vprod;
public Card RandomCardDraw()
{
sprod = Suite.Next(1, 5);
Card newc = new Card();
newc.x = sprod;
vprod = Value.Next(1, 13);
if (sprod == 1)
{
newc.suite = CardSuites.Club;
newc.y = vprod;
switch (vprod)
{
case 1:
newc.cardval = CardValues.Ace;
return newc;
case 2:
newc.cardval = CardValues.Two;
return newc;
case 3:
newc.cardval = CardValues.Three;
return newc;
case 4:
newc.cardval = CardValues.Four;
return newc;
case 5:
newc.cardval = CardValues.Five;
return newc;
case 6:
newc.cardval = CardValues.Six;
return newc;
case 7:
newc.cardval = CardValues.Seven;
return newc;
case 8:
newc.cardval = CardValues.Eight;
return newc;
case 9:
newc.cardval = CardValues.Nine;
return newc;
case 10:
newc.cardval = CardValues.Ten;
return newc;
case 11:
newc.cardval = CardValues.Jack;
return newc;
case 12:
newc.cardval = CardValues.Queen;
return newc;
case 13:
newc.cardval = CardValues.King;
return newc;
}
}
if (sprod == 2)
{
newc.suite = CardSuites.Diamond;
newc.y = vprod;
switch (vprod)
{
case 1:
newc.cardval = CardValues.Ace;
return newc;
case 2:
newc.cardval = CardValues.Two;
return newc;
case 3:
newc.cardval = CardValues.Three;
return newc;
case 4:
newc.cardval = CardValues.Four;
return newc;
case 5:
newc.cardval = CardValues.Five;
return newc;
case 6:
newc.cardval = CardValues.Six;
return newc;
case 7:
newc.cardval = CardValues.Seven;
return newc;
case 8:
newc.cardval = CardValues.Eight;
return newc;
case 9:
newc.cardval = CardValues.Nine;
return newc;
case 10:
newc.cardval = CardValues.Ten;
return newc;
case 11:
newc.cardval = CardValues.Jack;
return newc;
case 12:
newc.cardval = CardValues.Queen;
return newc;
case 13:
newc.cardval = CardValues.King;
return newc;
}
}
if (sprod == 3)
{
newc.suite = CardSuites.Heart;
newc.y = vprod;
switch (vprod)
{
case 1:
newc.cardval = CardValues.Ace;
return newc;
case 2:
newc.cardval = CardValues.Two;
return newc;
case 3:
newc.cardval = CardValues.Three;
return newc;
case 4:
newc.cardval = CardValues.Four;
return newc;
case 5:
newc.cardval = CardValues.Five;
return newc;
case 6:
newc.cardval = CardValues.Six;
return newc;
case 7:
newc.cardval = CardValues.Seven;
return newc;
case 8:
newc.cardval = CardValues.Eight;
return newc;
case 9:
newc.cardval = CardValues.Nine;
return newc;
case 10:
newc.cardval = CardValues.Ten;
return newc;
case 11:
newc.cardval = CardValues.Jack;
return newc;
case 12:
newc.cardval = CardValues.Queen;
return newc;
case 13:
newc.cardval = CardValues.King;
return newc;
}
}
if (sprod == 4)
{
newc.suite = CardSuites.Spade;
newc.y = vprod;
switch (vprod)
{
case 1:
newc.cardval = CardValues.Ace;
return newc;
case 2:
newc.cardval = CardValues.Two;
return newc;
case 3:
newc.cardval = CardValues.Three;
return newc;
case 4:
newc.cardval = CardValues.Four;
return newc;
case 5:
newc.cardval = CardValues.Five;
return newc;
case 6:
newc.cardval = CardValues.Six;
return newc;
case 7:
newc.cardval = CardValues.Seven;
return newc;
case 8:
newc.cardval = CardValues.Eight;
return newc;
case 9:
newc.cardval = CardValues.Nine;
return newc;
case 10:
newc.cardval = CardValues.Ten;
return newc;
case 11:
newc.cardval = CardValues.Jack;
return newc;
case 12:
newc.cardval = CardValues.Queen;
return newc;
case 13:
newc.cardval = CardValues.King;
return newc;
}
}
else
{
return newc;
}
return newc;
}
如果甲板上有1000張卡片,你會怎麼做? – I4V
這是處於非常早期的發展階段,我計劃在稍後實施更優雅的系統:) – user2649633
即使按照您的預期工作,「.Next(1,13)」永遠不會返回13. –