flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > RANDOM

Goto page Previous  1, 2, 3, 4
Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 19 Jan 2008, 02:16
Quote:
It makes we wonder if nature tries to communicate with us?

really wonder!
what can be the randomised methods the nature used to communicate with us?
because nature is the queen of random, she makes so many tries that now, we are all alive, human being exists because nature tries to make something that can walk on two legs and catch objects with hands...
we are the result of MILLION of years of random tries.
before us, there was dinosaur. very strange creatures.
they was randomised no?
or created to make some experiments...?
what is the code behind all these things???????????
what is this fuckin code?
i doubt it's xor, ror, not, neg or any asm instructions.
human is result of randomisation..
and more deeper, big bang is result of an other randomisation????
Post 19 Jan 2008, 02:16
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Jan 2008, 03:20
With so many philosophical posts I wonder if this thread is worth be kept at "Project and Ideas" forum Smile
Post 19 Jan 2008, 03:20
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 19 Jan 2008, 03:33
look at this, it makes some various randoms, and the first time i saw the effect of this very simple algorythm, i was doubting on the reality of the life.

please, can you post some other algorytms to make a big compilation of strange random algorythms.

this will find applications in various funy programs..
there are already the 256b demo site, but i don't know any program that contain all these effects.

some good idea is to make a sort of 3D engine textured with only things like this..
result can be very interresting and funny... Laughing


Description: really strange phenomenon, no?
Download
Filename: lifeB.zip
Filesize: 11.81 KB
Downloaded: 830 Time(s)

Post 19 Jan 2008, 03:33
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4153
Location: vpcmpistri
bitRAKE 19 Jan 2008, 19:27
If we have a pixel it is surrounded by eight other pixels:
Code:
???
?1?
???    
We could call these eight pixels the environment of pixel A, and represent this environment with a single byte. Pixel A can perform 256 different actions based on this environment.

1. Read environment
2. Take action
2a. change state: 0 or 1
2aa. change state of environment pixel: 0-7
2b. move pixel: 0 or 1
2bb. move active pixel: 0-7

It is rather easy to create a data driven algorithm for this:

;# get environment in AL
xlatb
;# change state?
;# move?

Randomly create blocks of 256 bytes, and a start position for pixel. If pixel doesn't do anything after some time - try again. Play with several on screen at once - different color planes. Could wrap screen or only keep the ones that stay on screen.

http://www.quinapalus.com/wi-index.html
http://www.ramos.nl/yyfire.html
http://mirekw.com/ca/index.html

Not random, the dynamics consist of both a fitness landscape and the water that rolls up that hill - figuratively speaking. Nature does not distinguish between code and data - everything executes - no programs are a mistake or error!

The code we see has no doubt cascaded from simplier times. I don't believe in truely random - some things are just beyond computablity.

[I've been very ill the last week and how the body responds is truely fastinating. A coordinated effort from many almost separate systems to erradicate a virtually unknown entity. It is a tricky thing to help the body do its work without also helping the virus.]
Post 19 Jan 2008, 19:27
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 19 Jan 2008, 19:51
[I've been very ill the last week and how the body responds is truely fastinating. A coordinated effort from many almost separate systems to erradicate a virtually unknown entity. It is a tricky thing to help the body do its work without also helping the virus.]

you're repaired now?
about illness, i've seen a very strange thing with a virus.
i was in bed, completelly halucinating cause i felt the millions of virii cells in my body, and with my mind, i told to all my body to fight against these virii, and it works.

since this date, i'm never ill.
approximately 8 years.
Post 19 Jan 2008, 19:51
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4153
Location: vpcmpistri
bitRAKE 21 Jan 2008, 00:10
[I rarely get sick - once every couple years. Today I am able to eat something without it being rejected. My head is not clear - which makes coding difficult. My daughter got sick first and I about 36 hours after. It feels good to be regaining strength.]
Post 21 Jan 2008, 00:10
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 21 Jan 2008, 02:09
illness is always a sad experience.

and it randomly appears.

i'm affraid, probability i get sick increase with the time i'm not...

or i have my quota, i was always ill when i was child, approximatelly 4 - 5 times a year...
i hope you'll can soon code an other random algorithm...it's not so difficult to do... but one little chalenge, make it like a function that we can call without any initialisation.
Post 21 Jan 2008, 02:09
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4153
Location: vpcmpistri
bitRAKE 21 Jan 2008, 02:55
Let me find the code for Wolfram's Rule 30.

Sorry, it is MASM syntax:
Code:
RULE_PAINT MACRO
     LOCAL _0, _1, _2, _3, _4
    push    ebx
 ;; pointer to DIB bits
      mov     esi, bi2_bits

   ;; skip first row
   mov     ecx, bi2.biWidth
    shr     ecx, 2+3 ; bits to DWORDs
   lea     edi, [esi + ecx*4]

;; build all rows from first...
;  neg     ecx
 push    bi2.biHeight
        push    ecx
 inc     DWORD PTR [esp+4]


   ; load rule lookup register
 movzx   eax, BYTE PTR [ebx].rule.rule
       ; all four bytes are same!
  mov     edx, 01010101h
      mul     edx
 mov     ebx, eax

_1: mov     ecx, [esp] ; dwords per line
        lea     esi, [esi+ecx*4]
    lea     edi, [edi+ecx*4]
    neg     ecx

     mov     ebp, [esi + ecx*4]
  bswap   ebp
 mov     edx, ebp ; ?
        rol     edx, 2
;     xor     edx, edx ; ?
        inc     ecx
_3:
; edx = ...| -2 | -1 | 0
  shr     edx, 2          ; get bit -1
        rcl     ebp, 3          ; 3 |...| 31 | -1 | 0 | 1
   ; save bit 2
        adc     edx, edx        ; ? |...| ? | 2

; rule bit 0
 bt      ebx, ebp
    rcl     eax, 1

  ; put bit 2 back
    rcr     edx, 1          ; ? |...| ?
 rcr     ebp, 3          ; 0 | 1 | 2 | ... | 31
      rol     ebp, 3          ; 3 |...| 31 | 0 | 1 | 2

        REPEAT 32-3
 ; rule bit 1 thru 29
                bt      ebx, ebp
            rcl     eax, 1
              rol     ebp, 1
      ENDM
        bt      ebx, ebp
    rcl     eax, 1


      mov     edx, [esi + ecx*4]
  bswap   edx

     shld    ebp, edx, 1
; rule bit 31
        bt      ebx, ebp
    rcl     eax, 1

  xchg    edx, ebp


    bswap   eax
 mov     [edi + ecx*4 - 4], eax

  inc     ecx
 jne     _3

      inc     DWORD PTR [esp+4]
   jne     _1

      add     esp, 8
      pop     ebx
ENDM    
Post 21 Jan 2008, 02:55
View user's profile Send private message Visit poster's website Reply with quote
FrozenKnight



Joined: 24 Jun 2005
Posts: 128
FrozenKnight 21 Feb 2008, 07:12
i wrote this a while back to generate large numbers of random numbers.
the r4d6m1 function is based on a statistical probably when you roll 4 dice and drop the lowest roll. it takes one parameter which is a 32 bit random or generated number in eax. (i made it for a friends D&D game. but decided to leave it there for posiable later use in rpg's LOL)

Code:
;my implementation of the
;Mersenne Twister Random algorithm
;by FrozenKnight

;call mt_init with a seed value to set up random
;call mt_random to get random value (note if you dont set it up it will set it's self up)
;also note that it uses shared memory so that the algorthim doesnt require to be set up a second time
;when mupital applications are using it.

format PE GUI 4.0 DLL
entry  DllStart

section '.edata' export data readable

dd 0,\                        ;Characteristics
   45984F00h                ;TimeDateStamp
dw 0,\                       ;MajorVersion
   1                   ;MinorVersion
dd RVA _szDllName,\   ;Name
   100,\              ;Base
   5,\                        ;NumberOfFunctions
   5,\                   ;NumberOfNames
   RVA _FuncAddrs,\  ;AddressOfFunctions
   RVA _NameAddrs,\     ;AddressOfNames
   RVA _OrdinalsAddrs        ;AddressOfNameOrdinals


_FuncAddrs:    ;must match sorted according to ordeal order
dd RVA MTRand
dd RVA MTinitMan;MTinit
dd RVA rand
dd RVA srand
dd RVA r4d6m1

_NameAddrs:    ;must be sorted
dd RVA _szMTinit
dd RVA _szMTRand
dd RVA _szr4d6m1
dd RVA _szrand
dd RVA _szsrand

_OrdinalsAddrs: ;must start at 0 and count up
dw 1               ;must match NameAddr order
dw 0
dw 4
dw 2
dw 3

_szDllName    db 'RAND.DLL', 0
_szMTRand db 'MTrand',0
_szMTinit    db 'MTinit',0
_szr4d6m1    db 'r4d6m1',0
_szrand      db 'rand',0
_szsrand       db 'srand',0


section '.text' code readable executable

align 8
DllStart:
;  call MTRand
;  call MTRand
;  call MTRand
;  call MTRand
  retn 4

align 8
srand:
  pop  eax
  pop    [_seed]
  jmp        eax


;this is a simple linear random function Primes gatehred from the rand function provided by the MSVC compiler
align 8
rand:
  mov eax, [_seed]
  mov edx, 214013
  mul edx
  add eax, 2531011
  shr eax, 16
  and eax, 7FFFh
  mov [_seed], eax
  ret

db 'FrozenKnight - If you use this please give me credit. ',\
   'i worked hard to get this to execute as fast as i could. Thank You.', 0

align 8
MTinitMan:
  mov         dword [mt_location], 623
align 8
MTinit:
  mov     [mt_initlized], 1
  mov      eax, [esp+4]
  mov   [mt_buffer], eax
  push      esi
  push   ecx
  push   edx
  mov    edx, 1
  mov         eax, mt_buffer
@@:
  mov      ecx, [eax]
  mov     esi, ecx
  shr       esi, 1Eh
  xor       esi, ecx
  imul      esi, 6C078965h
  add         esi, edx
  mov       [eax+4], esi
  add   eax, 4
  inc         edx
  cmp    eax, mt_buffer + (623*4)
  jl        @b
  pop     edx
  pop    ecx
  pop    esi
  retn   4

align 8  ;alignments used to speed up calls and jumps.
MTRand:
  push        ebx
  push   edx
  mov    ebx, mt_location
  dec       dword [ebx]
  js     .reseed
 .return:
  mov       eax, [ebx]
  ;---interlock---
  mov       eax, [mt_buffer+eax*4]
  ;---interlock---
  mov   ebx, eax
  ;---interlock---removed by changeing following ebx to eax

  sar    eax, 0Bh
  ;---interlock---
  xor         eax, ebx
  ;---interlock---
  mov         ebx, eax

  shl   eax, 7
  ;---interlock---
  and   eax, 0FF3A58ADh; 09D2C5680h
  ;---interlock---
  xor      eax, ebx
  ;---interlock---
  mov         ebx, eax

  shl   eax, 0Fh
  ;---interlock---
  and         eax, 0FFFFDF8Ch; 0EFC60000h
  ;---interlock---
  xor      eax, ebx
  ;---interlock---
  mov         ebx, eax

  sar   eax, 12h
  ;---interlock---
  xor         eax, ebx

  pop   edx
  pop    ebx                        
  retn

align 8
 .init:       ;i use a neat trick here that allows me to save
  rdtsc      ;a few cycles when calling these functions by allowing
  push      eax       ;the ruteen to return from it's call at a diffrent location
  push        .return
  jmp        MTinit
align 8
 .reseed:
  mov     eax, [mt_initlized]
  mov    dword [ebx], 623
  test      eax, eax
  jz        .init

  push     edi
  push   ebx
  push   ecx
  mov    edi, mt_buffer
  mov         ebx, mt_lookup
  push        dword [edi]
 .loop:
  cmp     edi, mt_buffer + (622 * 4)
  mov     ecx, [edi]
  jg      .final
  mov         edx, [edi+4]
  and   ecx, 80000000h
  and         edx, 7FFFFFFFh
  or          edx, ecx
  mov       ecx, edx
  mov       eax, [ebx]
  and     edx, 1
  shr         ecx, 1
  lea         edi, [edi+4]
  xor   ecx, [eax]
  lea     ebx, [ebx+4]
  xor   ecx, [mag01+edx*4]
  mov     [edi-4], ecx
  jmp   .loop
align 8
 .final:
  pop       edx
  and    eax, 80000000h
  and         edx, 7FFFFFFFh
  or          edx, eax
  mov       eax, [ebx]
  mov     ecx, edx
  and       edx, 1
  shr         ecx, 1
  ;---interlock---
  xor   ecx, [mt_buffer + 396*4]
  ;---interlock---
  xor         ecx, [mag01+edx*4]
  mov     [edi], ecx
  pop     ecx
  pop    ebx
  pop    edi
  jmp    .return

r4d6m1:
  push  ecx
  mov    ecx, [esp + 4*2]
  and       ecx, 0FFFFh
  mov    eax, 18
  cmp        ecx, 64473
  jg      .exit
  dec  eax
  cmp    ecx, 61742
  jg      .exit
  dec  eax
  cmp    ecx, 56989
  jg      .exit
  dec  eax
  cmp    ecx, 50365
  jg      .exit
  dec  eax
  cmp    ecx, 42274
  jg      .exit
  dec  eax
  cmp    ecx, 33577
  jg      .exit
  dec  eax
  cmp    ecx, 25132
  jg      .exit
  dec  eax
  cmp    ecx, 17648
  jg      .exit
  dec  eax
  cmp    ecx, 11479
  jg      .exit
  dec  eax
  cmp    ecx, 6877
  jg       .exit
  dec  eax
  cmp    ecx, 3742
  jg       .exit
  dec  eax
  cmp    ecx, 1820
  jg       .exit
  dec  eax
  cmp    ecx, 759
  jg        .exit
  dec  eax
  cmp    ecx, 253
  jg   .exit
  dec       eax
  cmp    ecx, 51
  jg .exit
  dec  eax
.exit:
  pop      ecx
  ret    4*1

section '.rdata' data readable ;writeable shareable
 ;N = 624
 ;M = 397
 mt_lookup: ;lookup table has a list of addresses to seed locations this allows for faster iterations.
  rept 227 kk
  {
    dd ((kk-1)+397)*4+mt_buffer
  }
  rept 397 kk
  {
    dd (kk-1)*4+mt_buffer
  }
; rolllookup:
;  dd 64473, 18
;  dd 61742, 17
;  dd 56989, 16
;  dd 50365, 15
;  dd 42274, 14
;  dd 33577, 13
;  dd 25132, 12
;  dd 17648, 11
;  dd 11479, 10
;  dd 6877,  9
;  dd 3742,  8
;  dd 1820,  7
;  dd 759,   6
;  dd 253,   5
;  dd 51,    4
;  dd 0,     3


section '.data' data readable writeable shareable
  ;UPPER_MASK    dd  0x80000000
  ;LOWER_MASK    dd  0x7fffffff

  mag01     dd  0
               dd  09908B0DFh

  mt_initlized    dd  0
  mt_location  dd  0 ;start at 0 location

  mt_buffer    dd    624 dup (?) ;mt seed values

  _seed        dd    ? ;MS rand seed values


section '.reloc' fixups data discardable    


i have used several optimizations to try to get the best possible speed from the algorithm. i may be able to optimize it further as i wrote it quite a while ago. note some calls may be much faster than others; as the algorithm has to re seed every 624 calls. you do not need to provide a seed to begin using this algorithm as i coded it to self seed if necessary.
Post 21 Feb 2008, 07:12
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3, 4

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.