func (d *dependencyFaultyDisk) reset() {
	d.mu.Lock()
	d.failDenominator = 0
	d.failed = false
	d.mu.Unlock()
}
reset resets the failDenominator and the failed flag of the dependency
package writeaheadlog
import (
	"io/ioutil"
	"os"
	"sync"
	"github.com/NebulousLabs/errors"
	"github.com/NebulousLabs/fastrand"
)
func scrambleData(d []byte) []byte {
	randomData := fastrand.Bytes(len(d))
	scrambled := make([]byte, len(d), len(d))
	for i := 0; i < len(d); i++ {
		if fastrand.Intn(4) == 0 {  
			scrambled[i] = randomData[i]
		} else {
			scrambled[i] = d[i]
		}
	}
	return scrambled
}
type dependencyFaultyDisk struct {
	disabled        bool
	failed          bool
	failDenominator int
	totalWrites     int
	writeLimit      int
	mu sync.Mutex
}
func newFaultyDiskDependency(writeLimit int) *dependencyFaultyDisk {
	return &dependencyFaultyDisk{
		writeLimit: writeLimit,
	}
}
func (d *dependencyFaultyDisk) create(path string) (file, error) {
	d.mu.Lock()
	defer d.mu.Unlock()
	if d.tryFail() {
		return nil, errors.New("failed to create file (faulty disk)")
	}
	f, err := os.Create(path)
	if err != nil {
		return nil, err
	}
	return d.newFaultyFile(f), nil
}
func (d *dependencyFaultyDisk) disable() {
	d.mu.Lock()
	d.disabled = true
	d.mu.Unlock()
}
func (*dependencyFaultyDisk) disrupt(s string) bool {
	return s == "FaultyDisk"
}
func (d *dependencyFaultyDisk) enable() {
	d.mu.Lock()
	d.disabled = false
	d.mu.Unlock()
}
func (d *dependencyFaultyDisk) tryFail() bool {
	d.totalWrites++
	if d.disabled {
		return false
	}
	if d.failed {
		return true
	}
	d.failDenominator += fastrand.Intn(13)
	fail := fastrand.Intn(int(d.failDenominator+1)) == 0  
	if fail || d.failDenominator >= d.writeLimit {
		d.failed = true
		return true
	}
	return false
}
func (d *dependencyFaultyDisk) newFaultyFile(f *os.File) *faultyFile {
	return &faultyFile{d: d, file: f}
}
func (*dependencyFaultyDisk) readFile(path string) ([]byte, error) {
	return ioutil.ReadFile(path)
}
func (d *dependencyFaultyDisk) remove(path string) error {
	d.mu.Lock()
	defer d.mu.Unlock()
	if d.tryFail() {
		return nil
	}
	return os.Remove(path)
}