English 中文(简体)
Assembly Random Number Using Irvine
原标题:Assembly Random Number Using Irvine

当我执行大会为我们提供的随机数字生成程序时,它给我以零差错的分辨率的一半,以及它完美运作的时间的一半。 我认为,我正在妥善执行该守则,但我将向各位介绍我是如何编写的。

randomCompNum PROC
    call Randomize               ;Sets seed
    mov  eax,10                  ;Keeps the range 0 - 9

    call RandomRange
    mov  compNum1,eax            ;First random number

L1: call RandomRange
    .IF eax == compNum1          ;Checks if the second number is the same as the first
        jmp L1                   ;If it is, repeat call
    .ENDIF
     mov compNum2,eax            ;Second random number

L2: call RandomRange
    .IF eax == compNum1          ;Checks if the third number is the same as the first
        jmp L2                   ;If it is, repeat
    .ELSEIF eax == compNum1      ;Checks if the third number is the same as the second
        jmp L2                   ;If it is, repeat
    .ENDIF
    mov compNum3,eax             ;Third random number stored

    ret

randomCompNum ENDP

在这里,RandomRange的视力场向我提供分餐

_RandomRange@0:
004019C1  push         ebx  
004019C2  push         edx  
004019C3  mov          ebx,eax  
004019C5  call         _Random32@0 (4019A6h)  ;<---- This function doesn t touch ebx
004019CA  mov          edx,0  
004019CF  div          eax,ebx     ;<---- That s where the error occurs
004019D1  mov          eax,edx  
004019D3  pop          edx  
004019D4  pop          ebx  
004019D5  ret

你们是否知道可以造成这一错误?

我只想制造我自己的随机的发电机。

Background on the RandomRange methods: 它很简单。 你把种子与兰芒混为一谈,把10个种子移至大轴中,兰芒语在南纬度之间。 页: 1 这是我为履行这一职责而找到的所有文件,因此,我完全相信会这样做。

问题回答

我认识到这是一个老问题,但我的朋友刚才提到了这个问题。

页: 1

randomCompNum PROC
    call Randomize               ;Sets seed

    mov  eax,10                  ;Keeps the range 0 - 9
    call RandomRange
    mov  compNum1,eax            ;First random number

L1: mov  eax,10                  ;Keeps the range 0 - 9
    call RandomRange
    .IF eax == compNum1          ;Checks if the second number is the same as the first
        jmp L1                   ;If it is, repeat call
    .ENDIF
     mov compNum2,eax            ;Second random number

L2: mov  eax,10                  ;Keeps the range 0 - 9
    call RandomRange
    .IF eax == compNum1          ;Checks if the third number is the same as the first
        jmp L2                   ;If it is, repeat
    .ELSEIF eax == compNum1      ;Checks if the third number is the same as the second
        jmp L2                   ;If it is, repeat
    .ENDIF
    mov compNum3,eax             ;Third random number stored

    ret
randomCompNum ENDP

The mov eax,10 is the parameter sent to the RandomRange function, it would be RandomRange(10); in C. Note that because RandomRange returns its result in eax, you need to set it up before each call.

Random32  PROC
;
; Generates an unsigned pseudo-random 32-bit integer
;   in the range 0 - FFFFFFFFh.

Random32 CAN 返回0,这很可能是为什么在你分裂时你被炸:-

Irvine的消息来源是可用的,只是修改RandomRange,处理从Random32返回的0时。





相关问题
Weighted random numbers

I m trying to implement a weighted random numbers. I m currently just banging my head against the wall and cannot figure this out. In my project (Hold em hand-ranges, subjective all-in equity ...

Comprehensive information about hash salts

There are a lot of questions about salts and best practices, however most of them simply answer very specific questions about them. I have several questions which feed into one another. Assuming a ...

Generate unique names?

I am working on a php site in which we have to upload images from users.i have to rename that file for preventing conflicts in the name of the image. uniqid(rand(), true); and adding a large random ...

How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

热门标签