Hello, When I try to generate random bytes using rand() or random() functions I found that these functions return constant values!? I am running: FreeBSD krassi 6.1-STABLE FreeBSD 6.1-STABLE #13: Tue Jul 11 13:41:31 EEST 2006 root@krassi:/usr/obj/usr/src/sys/MyKernel i386 sysctl kern.random kern.random.yarrow.gengateinterval: 10 kern.random.yarrow.bins: 10 kern.random.yarrow.fastthresh: 192 kern.random.yarrow.slowthresh: 256 kern.random.yarrow.slowoverthresh: 2 kern.random.sys.seeded: 1 kern.random.sys.harvest.ethernet: 1 kern.random.sys.harvest.point_to_point: 1 kern.random.sys.harvest.interrupt: 1 kern.random.sys.harvest.swi: 0 Best Regards
Krassimir Slavchev <krassi@bulinfo.net> writes:> When I try to generate random bytes using rand() or random() > functions I found that these functions > return constant values!?Show your code (preferably a minimal, compilable, example); chances are that you are not initializing the state properly for use of those functions. Note that those functions are not in any way related to the kernel random(4) device. I suspect this question would be more appropriate on FreeBSD-Questions; the version of FreeBSD you're running isn't really relevant.
On Thu, 21 Sep 2006, Krassimir Slavchev wrote:> When I try to generate random bytes using rand() or random() functions I > found that these functions return constant values!?Sounds pretty odd -- even if not explicitly seeded, you should be getting something pseudo-random, even if what you get is deterministic. Are you calling srandomdev() before invoking random()? Are you definitely using the result of invoking random() and not using the function pointer for random(), which will be constant? Robert N M Watson Computer Laboratory University of Cambridge> > I am running: > FreeBSD krassi 6.1-STABLE FreeBSD 6.1-STABLE #13: Tue Jul 11 13:41:31 EEST > 2006 root@krassi:/usr/obj/usr/src/sys/MyKernel i386 > > sysctl kern.random > kern.random.yarrow.gengateinterval: 10 > kern.random.yarrow.bins: 10 > kern.random.yarrow.fastthresh: 192 > kern.random.yarrow.slowthresh: 256 > kern.random.yarrow.slowoverthresh: 2 > kern.random.sys.seeded: 1 > kern.random.sys.harvest.ethernet: 1 > kern.random.sys.harvest.point_to_point: 1 > kern.random.sys.harvest.interrupt: 1 > kern.random.sys.harvest.swi: 0 > > > Best Regards > > _______________________________________________ > freebsd-stable@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-stable > To unsubscribe, send any mail to "freebsd-stable-unsubscribe@freebsd.org" >
Hmm, I missed to call srandomdev() before random(). Thanks for response Robert Watson wrote:> > On Thu, 21 Sep 2006, Krassimir Slavchev wrote: > >> When I try to generate random bytes using rand() or random() >> functions I found that these functions return constant values!? > > Sounds pretty odd -- even if not explicitly seeded, you should be > getting something pseudo-random, even if what you get is > deterministic. Are you calling srandomdev() before invoking > random()? Are you definitely using the result of invoking random() > and not using the function pointer for random(), which will be constant? > > Robert N M Watson > Computer Laboratory > University of Cambridge > >> >> I am running: >> FreeBSD krassi 6.1-STABLE FreeBSD 6.1-STABLE #13: Tue Jul 11 13:41:31 >> EEST 2006 root@krassi:/usr/obj/usr/src/sys/MyKernel i386 >> >> sysctl kern.random >> kern.random.yarrow.gengateinterval: 10 >> kern.random.yarrow.bins: 10 >> kern.random.yarrow.fastthresh: 192 >> kern.random.yarrow.slowthresh: 256 >> kern.random.yarrow.slowoverthresh: 2 >> kern.random.sys.seeded: 1 >> kern.random.sys.harvest.ethernet: 1 >> kern.random.sys.harvest.point_to_point: 1 >> kern.random.sys.harvest.interrupt: 1 >> kern.random.sys.harvest.swi: 0 >> >> >> Best Regards >> >> _______________________________________________ >> freebsd-stable@freebsd.org mailing list >> http://lists.freebsd.org/mailman/listinfo/freebsd-stable >> To unsubscribe, send any mail to >> "freebsd-stable-unsubscribe@freebsd.org" >> >-- Krassimir Slavchev Bulinfo Ltd. krassi@bulinfo.net (+359 2) 969-9160 http://www.bulinfo.net (+359 2) 969-9166