lseek for /dev/random

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
robfinch
Posts: 1
Joined: Sun Jun 22, 2025 12:28 am

lseek for /dev/random

Post by robfinch »

I am New at OSDev.

Implementing a device driver for a random number generator and wondering if lseek / tell should be implemented? It is possible to record the state of the generator which may allow an lseek to work. Seems kind of contrary to the idea of random numbers though.

The RNG uses George Marsaglia's multiply method.
nullplan
Member
Member
Posts: 1909
Joined: Wed Aug 30, 2017 8:24 am

Re: lseek for /dev/random

Post by nullplan »

Not every device is seekable, and the error code ESPIPE exists for that reason. Linux doesn't support seeking it, so I shouldn't think any application expects it to be seekable.
Carpe diem!
User avatar
iansjack
Member
Member
Posts: 4814
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: lseek for /dev/random

Post by iansjack »

I can't imagine why you would want to seek on /dev/random but I also don't see that it makes the generated numbers any less random than they are. For example, you wouldn't expect a SEEK_END to give the same results every time you called it, or indeed a predictable result.

I'm curious as to why you would consider implementing it.
Post Reply