News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

where is rand() ?

Started by w0lfshad3, September 02, 2006, 09:39:27 PM

Previous topic - Next topic

w0lfshad3

or what can i use instead?

can't locate it in the include

can i just PROTO it and includelib MSVCRT.LIB? (the msvcrt.lib from masm\lib is good or i should get it from somewhere else?)

Jackal

maybe what your looking for is the same as nrand.asm in \masm32\m32lib

Vortex

w0lf,

msvcrt.lib coming with masm32 works fine. All the functions are defined with the prefix crt_ to avoid conflicts with some reserved Masm keywords :

    externdef _imp__rand:PTR c_msvcrt
    crt_rand equ <_imp__rand>

w0lfshad3

Thank you tough i rather stick to srand and rand() for now my code needs to be initialized with the clock and the whole thing is documented. This nrand seems highly "pseudo" :) using constant numbers and all(perhaps rand does the same i haven't seen the asm replica tough).

Still anyone know how do i call rand() in my code?

Jackal

include \masm32\include\msvcrt.inc

includelib \masm32\lib\msvcrt.lib


invoke crt_rand, 20

w0lfshad3

i don't know what to do with this:
Quoteexterndef _imp__rand:PTR c_msvcrt
    crt_rand equ <_imp__rand>

This is the content of my msvcrt.inc lol:
sprintf   PROTO C :DWORD, :DWORD, :VARARG
printf    PROTO C :DWORD, :VARARG
wprintf   PROTO C :DWORD, :VARARG
_snprintf PROTO C :DWORD, :DWORD, :VARARG


Theres another msvcrt.000 should i include that? (so far i get an integer overflow error at run-time for some reason)

code: http://wolfshade.home.ro/int_overflow.asm

hutch--

hmmmmm,

> This nrand seems highly "pseudo" :) using constant numbers and all(perhaps rand does the same i haven't seen the asm replica tough).

This is why you objectively test a result instead of trying to form an opinion based on what you don't know. The test tool is John Walker's ENT available from the forum web site.

The C runtime rand() doresn't have a good history in terms of random output but if its good enough to do the job, its not like it matters much.

> This is the content of my msvcrt.inc lol: .......

If you wish to do your own, all you need to do is prototype the 700 odd functions in MSVCRT and you can do it any way you like.

> i don't know what to do with this:

externdef _imp__rand:PTR c_msvcrt
    crt_rand equ <_imp__rand>


Learn how to use INVOKE with an externally defined function making sure you use a library that matches the include files you use.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

w0lfshad3

QuoteThis is why you objectively test a result instead of trying to form an opinion based on what you don't know. The test tool is John Walker's ENT available from the forum web site.

? this phrase doesn't make any sense to me...

QuoteIf you wish to do your own, all you need to do is prototype the 700 odd functions in MSVCRT and you can do it any way you like.

Thats what i asked : QUOTEMYSELF: "can i just PROTO it and includelib MSVCRT.LIB?"

QuoteLearn how to use INVOKE with an externally defined function making sure you use a library that matches the include files you use.

I did use invoke no problem alltough i had to guess that .000 stands for .inc

Not one line in your post helps me one bit, perhaps you should be more explicit and also read what i said not missinterpret using prejudice coming from glancing over peoples text.

w0lfshad3

How to PROTO the rand() from msvcrt.lib from a VC environment for example?
I don't know how to PROTO the VOID type actually.

The error occurs at "; modulo" line as the debugger shows, i can't tell why.

http://wolfshade.home.ro/int_overflow.asm (i'm aware of the wrong pop bug, its not the reason)

hutch--

hmmmm,

> ? this phrase doesn't make any sense to me...

Learn how to read English then, the post quoted your own comments to give you the context.

Members have already shown you how to use the function from the C runtime library using the include file and library from the MASM32 project, if you wish to do it another way, feel free to create your own library and include file.

> Not one line in your post helps me one bit,

You can drag a dead horse to water but nothing will make it drink, your problem is you are trying to win an argument, not learn how to do something that is very simple like calling a C runtime function from MASM.

> perhaps you should be more explicit and also read what i said not missinterpret
> using prejudice coming from glancing over peoples text.

Perhaps you should bother to read the replies you already have instead of trying to win an argument. This is not a paid help desk, members have tried to help you and so far you have exhibited bad manners in response to their efforts.

> How to PROTO the rand() from msvcrt.lib from a VC environment for example?
> I don't know how to PROTO the VOID type actually.

It would help if you bothered to look up the function on MSDN and see what the return value is, in MASM you are not writing C and you should know by now where a return value comes from. HINT : it will be in EAX.

Now I will give you one more warning, keep trying to look for an argument here and you will be given the opportunity to find that virus venue you were so interested in.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

w0lfshad3

added ", NULL" in the invoke crt_rand, NULL error still comes from the "; modulo" line

QuoteIt would help if you bothered to look up the function on MSDN and see what the return value is, in MASM you are not writing C and you should know by now where a return value comes from. HINT : it will be in EAX.

Again i knew and did that;

div temp(1)...

Unsigned divide EDX:EAX by r/m32,
with result stored in EAX ← Quotient,
EDX ← Remainder.

What is the reason for the bug?

QuoteNow I will give you one more warning, keep trying to look for an argument here and you will be given the opportunity to find that virus venue you were so interested in.

I never was interested in no virus. If you are refering to the post "dilema" read the first post in the thread, i'm asking for the path of knowledge to be hired in an AV company not the path to knowledge of creating a virus. In fact i have on my HDD virus tutorials for about 6 years from a bulk of data coming from an buddy and never cared about it, creating viruses doesn't make money except for AV companies. In fact there is a remarcable observation that can be made: everyone who had something bad to say in that post never ever really helped me in any of the many questions i placed in here. A good programmer does not necessarely make a good teacher. In the description of the Campus forum there are some rules yet in reality there is a lot of harassing in here. Either ban me if it will make you feel better or stop haunting me for no reason.

hutch--

Is it that hard to do what members have already shown you how to do ? Same old problem, try reading what the members have already shown yourather than trying to win an argument.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc


    push esi
    mov esi, 16

  @@:
    invoke crt_rand,12345678
    print str$(eax),13,10
    sub esi, 1
    jnz @B

    pop esi

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start


Output is,


41
18467
6334
26500
19169
15724
11478
29358
26962
24464
5705
28145
23281
16827
9961
491
Press any key to continue ...


As far aas this nonsense,

Quote
I never was interested in no virus. If you are refering to the post "dilema" read the first post in the thread, i'm asking for the path of knowledge to be hired in an AV company not the path to knowledge of creating a virus. In fact i have on my HDD virus tutorials for about 6 years from a bulk of data coming from an buddy and never cared about it, creating viruses doesn't make money except for AV companies. In fact there is a remarcable observation that can be made: everyone who had something bad to say in that post never ever really helped me in any of the many questions i placed in here. A good programmer does not necessarely make a good teacher. In the description of the Campus forum there are some rules yet in reality there is a lot of harassing in here. Either ban me if it will make you feel better or stop haunting me for no reason.

The person who admits he has a set of virus tutorial on his hard disk has little to tell anyone else. As before you will never get support for ANY form of virus techbnology here and after hearing every piece of bullsh*t for years from these idiots, it would not be wise to hold your breath waiting for a change in policy. You have been told before that neither the admin or the members need your advice when it comes to running this forum, that is not going to change either.

Basing your value judgements on your failure to win an argument does not convince anyone so do us all a favour and give up on the idea.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Jackal

Quote from: Jackal on September 02, 2006, 10:59:23 PM
include \masm32\include\msvcrt.inc

includelib \masm32\lib\msvcrt.lib


invoke crt_rand, 20


This shows how to include the proper files and call the function. I am a beginner here and from just this it makes sense to me. If this does not help then i dont know what will.

w0lfshad3


Same story for msvcrt.000

Jackal i am doing that from way behind when i fixed the 1 argument it takes. It still has the same error as if the argument has no meaning in the function.

hutch--

Check that you have built the msvcrt library with your installation of masm32. You should have both MSVCRT.INC and LIB in the respective directories.

Here is the next version showing reseeding the algo and a direct comparison with nrandom that is faster and has a larger range.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    LOCAL cnt   :DWORD

    mov cnt, 4

    push esi

  ; =================================

    invoke GetTickCount         ; use as seeed source
    push eax
    invoke crt_srand, eax

  outer:
    mov esi, 4

  inner:
    invoke crt_rand,32768       ; rand() has 32k range
    push eax
    print str$(eax),13,10       ; display result
    pop eax
    sub esi, 1
    jnz inner

    invoke crt_srand, eax       ; reseed using every 4th result
    sub cnt, 1
    jnz outer

  ; =================================

    mov cnt, 4
    pop eax
    invoke nseed,eax            ; reuse same seed

  lbl1:
    mov esi, 4

  lbl2:
    invoke nrandom,32768        ; nrandom has signed DWORD range (2 gig)
    push eax
    print str$(eax),13,10       ; display result
    pop eax
    sub esi, 1
    jnz lbl2

    invoke nseed,eax            ; reseed using every 4th result
    sub cnt, 1
    jnz lbl1

  ; =================================

    pop esi

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php