googleinterns/step224-2020

Create a file generating function

Closed this issue · 3 comments

We want to use a pseudo-random byte generator using math/rand in go to generate file contents

Include generating the file name here (as per Cian's comment):

Example function signature:
func GiveMeAFile(int id, int64 size) (string, io.LimitedReader)

With LimitedReader supplying the file contents.

Working on this now.

For the mutex locking we can use something similar to the private read() method in math/rand:

We will need to implement a locked source ourselves first.

// read implements Read for a lockedSource without a race condition.
func (r *lockedSource) read(p []byte, readVal *int64, readPos *int8) (n int, err error) {
	r.lk.Lock()
	n, err = read(p, r.src, readVal, readPos)
	r.lk.Unlock()
	return
}