问题描述
我正在用 nasm 进行大学项目.唯一的问题是我无法生成 162 到 278 之间的偶数随机数.我尝试了很多算法,但似乎无法限制范围内的数字.
I am working on a university project in assembly nasm. The only problem is i am not able to generate an even random number between 162 and 278. I have tried many algorithms but cant seem to restrict the number in range.
是否有一个小技巧或调整可以在范围内获得所需的数字?目的是在屏幕上随机显示一个水果(主要是蛇游戏).
Is there a small trick or tweak to get the desired number in range? The aim is to display a fruit randomly on the screen(It is mainly a snake game).
推荐答案
我看了一下这篇文章:nasm 随机数生成器函数.也许你可以试试 (rdtsc % (278 - 162)/2 + 162/2) * 2.希望对你有帮助:)
I look a little bit in this post: nasm random number generator function.Maybe you can try (rdtsc % (278 - 162) / 2 + 162 / 2) * 2.I hope I helped you :)
这篇关于装配 NASM 中的随机数生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!