egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

regarding the dice.tcl script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
crappuccino
Voice


Joined: 22 Sep 2006
Posts: 6

PostPosted: Fri Sep 22, 2006 12:12 am    Post subject: regarding the dice.tcl script Reply with quote

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 Wink

thanks for your time
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Fri Sep 22, 2006 1:34 am    Post subject: Reply with quote

Possibly contact the author?
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
crappuccino
Voice


Joined: 22 Sep 2006
Posts: 6

PostPosted: Fri Sep 22, 2006 2:40 am    Post subject: Reply with quote

it's a dude called KuNgFo0, i thought he would be somehow related to this forum as he is mentioned at the main page Wink
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Fri Sep 22, 2006 3:28 am    Post subject: Reply with quote

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 Wink

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
Back to top
View user's profile Send private message Visit poster's website
crappuccino
Voice


Joined: 22 Sep 2006
Posts: 6

PostPosted: Fri Sep 22, 2006 3:53 am    Post subject: Reply with quote

his page hasn't been responding for 2 days, that's why i came here in the first place Confused
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Sep 22, 2006 7:22 am    Post subject: Reply with quote

Quote:

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
Back to top
View user's profile Send private message
crappuccino
Voice


Joined: 22 Sep 2006
Posts: 6

PostPosted: Fri Sep 22, 2006 5:22 pm    Post subject: Reply with quote

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 Wink
but i mistook the entropy_avail number for bytes instead of bits Confused
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Sep 22, 2006 9:08 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
crappuccino
Voice


Joined: 22 Sep 2006
Posts: 6

PostPosted: Sat Sep 23, 2006 11:53 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Sep 24, 2006 2:17 pm    Post subject: Reply with quote

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:

#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 Smile

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.
Back to top
View user's profile Send private message
crappuccino
Voice


Joined: 22 Sep 2006
Posts: 6

PostPosted: Mon Sep 25, 2006 2:57 am    Post subject: Reply with quote

hum, thanks for your effort, i'm going to sit awhile trying to figure out what that means Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber