|
发表于 2023-6-24 00:01:30
|
显示全部楼层
本帖最后由 wuliangtdi 于 2023-6-24 00:03 编辑
稍微修改了一下:
csharp:
- namespace TestRandCSharp
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string[] s = {"鸡你太美", "荔枝", "你干嘛~嗨嗨哎哟~", "近一点快被融化", "多一眼就会爆炸"};
- Random random = new Random();
- String? total = null;
- while (true)
- {
- int xia = random.Next(0, 5);
- int a = random.Next(100, 300);
- total = new String(' ',a);
- Console.Write(s[xia]);
- Console.Write(total);
- total = null;
- //延迟一段时间,降低输出速度
- Thread.Sleep(1000);
- }
- }
- }
- }
复制代码
CPP:
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- string s[] = {"鸡你太美", "荔枝", "你干嘛~嗨嗨哎哟~", "近一点快被融化", "多一眼就会爆炸"};
- srand(static_cast<unsigned>(time(NULL)));
- while (true)
- {
- int xia = rand() % 5 + 0;
- int a = rand() % 200 + 100;
- cout << s[xia];
- string spaces(a, ' ');
- cout << spaces;
- }
- return 0;
- }
复制代码
|
|