我正在为一个使用 Pascal 变体的班级作业运行 Fenuc Karel 机器人,但是我们的机器人是从 1991 年到 1993 年在他们添加 random() 之前。有谁知道如何在 Pascal 的旧 dos 实现上获取随机数?请注意,因为年龄变量名称不能超过 8 个字符,数字不能超过 255
1 回答
1
If it is a borland pascal version, you can use asm { … }
blocks, which would allow you to get a value from the RTC, which is sufficiently random for many intents and purposes. Given a variable random:
asm {
xor ax, ax;
int 1ah;
mv random, al;
}
This would give you the last 8 bit of the real time clock value.
Apart from that you could look for pseudorandom number generation on old machines, e.g. C64; though you'd have to port the code to pascal.
Update: It appears, Fanuc Karel (I hope this is it) has a GET_TIME routine, though I'm unsure about what that returns.
于 2015-01-29T13:35:39.050 回答