This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

regarding the dice.tcl script

Support & discussion of released scripts, and announcements of new releases.
Post Reply
c
crappuccino
Voice
Posts: 6
Joined: Fri Sep 22, 2006 12:03 am

regarding the dice.tcl script

Post by crappuccino »

hi,
i'm having the problem that dice.tcl takes far too much entropy from /dev/random. it seems to always drain the complete pool, so subsequent rolls get delayed by ages. i just rolled a d20 and it used up 520 bytes of entropy when it only needs 5 bits. is there a way to change this? i have absolutely no clue about tcl scripting or a way to retrieve the proper number of bits from /dev/random.
oh and i don't like the idea of using urandom or another pseudogenerator ;)

thanks for your time
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Possibly contact the author?
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
c
crappuccino
Voice
Posts: 6
Joined: Fri Sep 22, 2006 12:03 am

Post by crappuccino »

it's a dude called KuNgFo0, i thought he would be somehow related to this forum as he is mentioned at the main page ;)
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

crappuccino wrote:it's a dude called KuNgFo0, i thought he would be somehow related to this forum as he is mentioned at the main page ;)
As far as I am aware KuNgFo0 has never been a member; I think there is a link to his website on the main egghelp.org page (which does not indicate affiliation with these forums).

His script/website will have contact details.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
c
crappuccino
Voice
Posts: 6
Joined: Fri Sep 22, 2006 12:03 am

Post by crappuccino »

his page hasn't been responding for 2 days, that's why i came here in the first place :?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

RANDOM(4) Linux Programmer's Manual RANDOM(4)

NAME
random, urandom - kernel random number source devices

DESCRIPTION
The character special files /dev/random and /dev/urandom (present since Linux 1.3.30) provide an interface to the kernel's random number generator. File /dev/random has major device number 1 and minor device number 8. File /dev/urandom has major device number 1 and minor device number 9.

The random number generator gathers environmental noise from device drivers and other sources into an entropy pool. The generator also keeps an estimate of the number of bit of the noise in the entropy pool. From this entropy pool random numbers are created.

When read, the /dev/random device will only return random bytes within the estimated number of bits of noise in the entropy pool. /dev/random should be suitable for uses that need very high quality randomness such as one-time pad or key generation. When the entropy pool is empty, reads to /dev/random will block until additional environmental noise is gathered.

When read, /dev/urandom device will return as many bytes as are requested.
Doesn't look like there is a way to limit the number of bites returned by /dev/random
c
crappuccino
Voice
Posts: 6
Joined: Fri Sep 22, 2006 12:03 am

Post by crappuccino »

sklave ~ # cat /proc/sys/kernel/random/entropy_avail
202
sklave ~ # dd if=/dev/random of=./bla.txt bs=8 count=1
1+0 records in
1+0 records out
8 bytes (8 B) copied, 6.3e-05 seconds, 127 kB/s
sklave ~ # ls -l
total 4
-rw-r--r-- 1 root root 8 Sep 22 23:18 bla.txt
sklave ~ # cat /proc/sys/kernel/random/entropy_avail
168

to me it looks like there is ;)
but i mistook the entropy_avail number for bytes instead of bits :?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I've been looking at the dice script, and I'm thinking that you might need to use fconfigure to set the encoding type to binary, and also set the buffersize to it's smallest limit (which is 10 bytes.) Check the manpages for tcl's 'binary' and 'fconfigure' commands. I haven't tried it, but I'm certainly curious at this point <grin>

Let us know if that helps.
c
crappuccino
Voice
Posts: 6
Joined: Fri Sep 22, 2006 12:03 am

Post by crappuccino »

uhm, as stated before, i don't know jack about tcl or coding in general, so even if i somehow figured out the right fconfigure command, i wouldn't even know where to put it ;)
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

I just tested the dice script myself, I do not see it impacting the entropy_avail at all:

cat /proc/sys/kernel/random/entropy_avail
4096

I ran the script 4-5 times and put in debug statements so I could see what the script is doing:

<rosc> .dice
[theentity(dcc)] [13:36] using file /dev/random
[theentity(dcc)] [13:36] rand 1516153535
[theentity(dcc)] [13:36] using file /dev/random
[theentity(dcc)] [13:36] rand 816658326
<TheEntity> rosc, 2d6: 2, 4 [Total: 6 (Avg), Avg: 3.00]
<rosc> .dice
[theentity(dcc)] [13:36] using file /dev/random
[theentity(dcc)] [13:36] rand 1692811833
[theentity(dcc)] [13:36] using file /dev/random
[theentity(dcc)] [13:36] rand -22754210
<TheEntity> rosc, 2d6: 2, 1 [Total: 3 (Low), Avg: 1.50]

cat /proc/sys/kernel/random/entropy_avail
4096

Then I made this change to the script:

Code: Select all

#antiwordwrapline###################################################################################################################

                   foreach f {/dev/random} {
                                if {[file exists $f]} { set file $f }
                   }
                   if {![info exists file]} {
                                error "Could not find a suitable random file" 
                   } elseif {[catch {open $file r} fileid]} { 
                                error "Could not open random file '$file'"
                   } elseif {![catch {fconfigure $fileid -buffersize 10} error] && ![binary scan [read $fileid 4] i rand]} {
                                close $fileid ; error "Random file '$file' gave weird input"
                   } else {
                                putcmdlog "[fconfigure $fileid]"
                                putcmdlog "using file $fileid"  
                                putcmdlog "rand $rand"
                                close $fileid
                                return [expr {($rand & $maxint - 1) / double($maxint)}]
                   }
And this is what my log shows:

<rosc> .dice
[theentity(dcc)] [14:00] -blocking 1 -buffering full -buffersize 10 -encoding iso8859-1 -eofchar {} -translation auto
[theentity(dcc)] [14:00] using file file20
[theentity(dcc)] [14:00] rand 1592478028
[theentity(dcc)] [14:00] -blocking 1 -buffering full -buffersize 10 -encoding iso8859-1 -eofchar {} -translation auto
[theentity(dcc)] [14:00] using file file20
[theentity(dcc)] [14:00] rand -320820591
<TheEntity> rosc, 2d6: 2, 1 [Total: 3 (Low), Avg: 1.50]


I also tried it with -buffersize 15, and saw the appropriate change in the log:
[theentity(dcc)] [13:59] -blocking 1 -buffering full -buffersize 15 -encoding iso8859-1 -eofchar {} -translation auto

In all the tests I did, none of them impacted entropy_avail:
cat /proc/sys/kernel/random/entropy_avail
4096

Just in case it's relevent, my kernel version is:
uname -a
Linux xanadu 2.4.32 #1 SMP Sun Dec 11 20:45:49 EST 2005 i686 unknown

One last note, when I was testing the various random number generators, the results from the "eggdrop" option were somewhat better than the other options, at least IMO :)

edit:
I should also note that changing the buffer size did not affect the number of bits returned (it was 10, regardless of buffersize being set to 15) so I'm assuming the script already does limit the number of bits it grabbed, eg,

[binary scan [read $fileid 4] i rand]

read channelId numChars

and

binary scan i

i
The data is interpreted as count 32-bit signed integers represented in little-endian byte order. The integers are stored in the corresponding variable as a list. If count is *, then all of the remaining bytes in [50]string will be scanned. If count is omitted, then one 32-bit integer will be scanned. For example,

binary scan \x05\x00\x00\x00\x07\x00\x00\x00\xf0\xff\xff\xff i2i* var1 var2
will return 2 with 5 7 stored in var1 and -16 stored in var2.
c
crappuccino
Voice
Posts: 6
Joined: Fri Sep 22, 2006 12:03 am

Post by crappuccino »

hum, thanks for your effort, i'm going to sit awhile trying to figure out what that means :D
Post Reply