de.sciss.lucre.InTxnRandom.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lucre-core_3 Show documentation
Show all versions of lucre-core_3 Show documentation
Extension of Scala-STM, adding optional durability layer, and providing API for confluent and reactive event layers
The newest version!
/*
* InTxnRandom.scala
* (Lucre 4)
*
* Copyright (c) 2009-2024 Hanns Holger Rutz. All rights reserved.
*
* This software is published under the GNU Affero General Public License v3+
*
*
* For further information, please contact Hanns Holger Rutz at
* [email protected]
*/
package de.sciss.lucre
import de.sciss.lucre.impl.RandomImpl.{BaseImpl, calcSeedUniquifier, initialScramble}
import scala.concurrent.stm.{InTxn, Ref => STMRef}
object InTxnRandom {
def apply(): Random[InTxn] = apply(calcSeedUniquifier() ^ System.nanoTime())
def apply(seed: Long): Random[InTxn] = new Impl(STMRef(initialScramble(seed)))
private final class Impl(seedRef: STMRef[Long]) extends BaseImpl[InTxn] {
def rawSeed_=(value: Long)(implicit tx: InTxn): Unit = seedRef() = value
def rawSeed (implicit tx: InTxn): Long = seedRef()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy