|
 |
|
C# winApp ไม่ทราบว่าแก้ไขข้อผิดพลาดการสุ่มแบบนี้ยังไง ครับ |
|
 |
|
|
 |
 |
|
ผมได้ แยก List<string> ออกเป็น
wordA ที่เป็นคำศัพท์ ภาษษอังกฤษ
และ wordB ที่เก็บคำแปลไว้
ทำการสุ่ม จากนั้นก็ตัดคำที่สุ่มออกไปทุกคั้ง
ผลปรากฏว่า ตัวท้ายของการสุ่ม คำศัพท์ และ คำแปลไ จะตรงกันทุกหน้า ครับ
https://github.com/mongkonP/KidsLearning
prnEng002WordLine.cs
Code (C#)
for (int i = 0; i < 10; i++)
{
int z = (wordA.Count == 1) ? 0 : RandomNumberGenerator.GetInt32(0, wordA.Count - 1);
e.Graphics.DrawString(wordA[z], new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 5, yC + 5);
wordA.RemoveAt(z);
z = (wordB.Count == 1) ? 0 : RandomNumberGenerator.GetInt32(0, wordB.Count - 1);
e.Graphics.DrawString(wordB[z], new Font("Angsana New", 22), new SolidBrush(Color.Black), xC + 350, yC + 5);
wordB.RemoveAt(z);
yC += 60;
}

ไม่เข้าใจว่าโค้ดผิดตรงไหน หรือปล่าว
Tag : .NET, C#

|
|
 |
 |
 |
 |
Date :
2022-10-25 16:29:10 |
By :
lamaka.tor |
View :
525 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator.getint32?view=net-6.0#system-security-cryptography-randomnumbergenerator-getint32(system-int32-system-int32)
RandomNumberGenerator.GetInt32 Syntax
public static int GetInt32 (int fromInclusive, int toExclusive);
toExclusive คือ ไม่นับรวม
Code (C#)
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
List<string> wordA = new List<string> {
"A", "B", "C", "D", "E", "F"
};
List<string> wordB = new List<string> {
"เอ", "บี", "ซี", "ดี", "อี", "เอฟ"
};
for (int i = 0; i < 6; i++)
{
string line = string.Empty;
int z = (wordA.Count == 1) ? 0 : RandomNumberGenerator.GetInt32(0, wordA.Count);
line = wordA[z] + " ";
wordA.RemoveAt(z);
z = (wordB.Count == 1) ? 0 : RandomNumberGenerator.GetInt32(0, wordB.Count);
line += wordB[z];
wordB.RemoveAt(z);
Console.WriteLine(line);
}
}
}
}
Out
F เอ
D ซี
B บี
C เอฟ
E ดี
A อี
|
 |
 |
 |
 |
Date :
2022-10-26 10:21:56 |
By :
009 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|