c - Finding Allocated Memory -


  • platform: x86 linux 3.2.0 (debian 7.1)
  • compiler: gcc 4.7.2 (debian 4.7.2-5)

i writing function generates "random" integer reading allocated portions of memory "random" values. idea based on fact uninitialized variables have undefined values. initial idea allocate array using malloc() , use uninitialized elements generate random number. malloc() tends return null blocks of memory cannot guarantee there read. thought reading separate processes memory in order guarantee values other null. current idea somehow finding first valid memory address , reading there down not know how this. tried initializing pointer null , incrementing 1 if attempt print referenced memory location segmentation fault occurs. question how read separate processes memory. not need memory other read it.

the idea based on fact uninitialized variables have undefined values.

they undefined in far cannot predict contain. os dependent contain.

back in old dos days, maybe rely on fact if executed several programs in current session, there garbage in memory. data wasn't reliable source of randomness.

nowadays, things different.

  • if have variables on stack, , in corrent program run never deep on stack now, local variables 0. otherwise, contain data previous function calls.

  • if malloc() , libc takes returned memory pool of used memory, might contain garbage well. if newly gets os, zeroed.

my initial idea allocate array using malloc() , use uninitialized elements generate random number. malloc() tends return null blocks of memory cannot guarantee there read.

(not null, 0 or nul.) see last point: depends on history of malloc()ed area.

so thought reading separate processes memory in order guarantee values other null.

you cannot, processes separated , shielded each other.

as others said, there better sources of randomness. /dev/random if need real entropy, /dev/urandom otherwise.


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -