1665500100
The rationale for this crate is to generate good quality random numbers fast, simply and with a minimal footprint.
Not everyone wants to add 375 kB, plus another ten dependencies, just to generate a bunch of random numbers for testing ( looking at the 'other' crate: rand
).
In contradistinction, this crate is lightweight and it has no dependencies.
Even so, there are four different algorithms on offer, plus a good range of utility functions to easily generate individual numbers of various types, vectors, and vectors of vectors filled with random numbers.
The main objective has been the ease of use rather than flat-out speed but the algorithms are neverheless very fast.
It is highly recommended to read and run tests/tests.rs
with examples of usage.
use ran::*; or
use ran::{set_seeds,RE,Rnum,Rv,Rvv};
These algorithms use thread safe static seeds. It is strongly recommended to initialise them with set_seeds(value);
in every thread where you may want to be generating random numbers, otherwise you will get the same sequence every time, based on the default value. Any u64 value will do to initiate a new, different, random sequence. Of course, the same seed will always produce the same sequence and this is sometimes actually useful for exact testing comparisons.
/// This function initialises SEED and xoshi seeds X0-X3.
/// The supplied value must be non zero,
/// otherwise seeds will remain unchanged.
pub fn set_seeds( seed:u64 )
Simple instructive example to generate a dxn matrix of random bytes:
let matrix = Rnum::newu8().ranvv(d, n)?.getvvu8()?;
First we created Rnum instance for the required type (u8). This can be saved with let statement and reused for repeated generations of values, vectors and matrices of the same end type. Next we call on it generic method ranv(d,n)
, that generates random numbers. Finally, we retrieve the matrix from its wrapper with getvvu8()
. The last two methods must agree on the target object, in this case both indicate vv
= vec of vecs
. They both potentially return custom error RE
: here we are just passing it up with the ?
operator.
Polymorphic interface avoids having to use different typed functions for each primitive type. This can be too repetitive, given that there are quite a few primitive numeric types. Nevertheless, such typed functions are also available in (use ran::generators::*;
). They can be used in simple applications directly (see below, section Explicitly Typed Functions).
In lib.rs
we define three polymorphic (generic) enum types:
/// Wrapper for enum polymorphism - single value
pub enum Rnum {
F64(f64), U64(u64), I64(i64), U16(u16), U8(u8)
// Should be extended to cover all numeric types?
}
/// Wrapper for enum polymorphism - vectors
pub enum Rv {
F64(Vec<f64>), U64(Vec<u64>), I64(Vec<i64>), U16(Vec<u16>), U8(Vec<u8>)
}
/// Wrapper for enum polymorphism - vectors of vectors
pub enum Rvv {
F64(Vec<Vec<f64>>),
U64(Vec<Vec<u64>>),
I64(Vec<Vec<i64>>),
U16(Vec<Vec<i16>>),
U8(Vec<Vec<u8>>)
}
Their filling with random numbers of required types is done by their associated functions
, defined in module impls.rs
. First create an instance of one of these types. For single random numbers, it will be enum type Rnum
, of the variant corresponding to the end-type of the random numbers wanted.
Rnum, Rv, Rvv
are just wrapper enum types, serving to communicate to the generic method(s) information about the actual type of the (random) number(s) wanted. The following example shows how to create instance variables for all them:
let rf = Rnum::newf64();
let ru = Rnum::newu64();
let ri = Rnum::newi64();
let ru16 = Rnum::newu16();
let ru8 = Rnum::newu8();
We can then apply common generic method(s) to all such variables to generate the required random numbers. For example:
println!("Random numbers in specified ranges: {}, {}, {}, {}",
rf.rannum_in(0.,100.), // wrapped f64 value 0. to 100.
ru.rannum_in(1.,1000.), // wrapped u64, 1 to 1000 (inclusive)
ri.rannum_in(-10.,10.), // wrapped i64, -10 to 10 (inclusive)
ru16.rannum_in(60000.,65535.), // u16, 60000 to 65535
ru8.rannum_in(1.,6.) // wrapped u8, 1 to 6 (inclusive)
);
They all print because Display
has been implemented for these three enum types. Their inner wrapped values can be if let
pattern extracted as follows:
use anyhow::{Result,bail};
if let Rnum::F64(x) = rf { utilise the x:f64 value }
else { bail!("rf does not hold value of f64 type!") };
The else branch can be used to report disappointed type expectations, as shown (assuming here that anyhow
crate is being used for error handling). Alternatively, else
can be used to return some default value, e.g. {0_f64}
or it can be dismissed with a semicolon, using if let
as a statement, rather than as an expression. In this case, should this particular extraction attempt fail, it will be just ignored:
// wrapped vec of random u8 values
if let Rv::U8(vx) = ru8.ranv_in(20,1.,6.)?
{ println!("Dice roll sequence: {}", stringv(&vx)) };
This example illustrated the use of enum type Rv
, used for vector of random numbers. As can be seen, its variants are extracted in the same way as from Rnum
. (The helper function stringv
from module secondary.rs
converted the extracted vector to a String to facilitate its printing). Of course, Rv type object (unextracted) would print as it is.
There is also enum type Rvv
for returning vectors of vectors of random numbers:
// vec of vecs using ranvv_in(d,n,min,max) and Display of Rvv
println!(
"5x5 matrix of integers in range [-10,10]:\n{}",
ri.ranvv_in(5,5,-10.,10.)?
);
stringvv
is another utility function to enable display of generic vectors of vectors. We did not need to use it here since Dislay
is implemented for Rvv
type and we did not bother to extract the wrapped value (vector of vectors).
The results wrapped within all three return types: Rnum,Rv,Rvv
can all be pattern extracted as needed with if let
.
Alternatively, for convenience, they can all be extracted with supplied get
methods. Their names follow this syntax: get{|v|vv}end_type()
.
// the following line tests 'getvi64()'
let pairofints = ri.ranv(2)?.getvi64()?;
println!("2 random i64s: {}", stringv(&pairofints));
Initialisation: the Self produced is Rnum
type and will contain the default value zero of the required numeric end type.
pub fn newf64() -> Self
pub fn newu64() -> Self
pub fn newi64() -> Self
pub fn newu16() -> Self
pub fn newu8() -> Self
The following methods are all implemented for Rnum
, that means invoked on Rnum
type variable. Even when generating Rv
or Rvv
type results. Rnum
type input variable (self
) in all cases serves just to inform the generic method about the numeric type required for the generated values:
pub fn rannum(&self) -> Self
returns a wrapped random number of one of the main types in maximum range allowed by the width of the type. The standardised range [0,1) is used for f64
.
pub fn rannum_in(&self,min:f64,max:f64) -> Self
returns a wrapped random number of one of the main types in the range min,max (min,max are always f64
s for commonality). The range should not exceed the width of the type, e.g. 0.,255. for u8
. Nor should it be negative for unsigned types.
pub fn ranv(&self,d:usize) -> Result<Rv,RE>
Rv value is a wrapped Vec of length d filled with random numbers of one of the main primitive types. Note that the whole Vec
is wrapped, not each individual element of it. Thus only one pattern extraction is needed.
pub fn ranv_in(&self,d:usize,min:f64,max:f64) -> Rv
same as ranv
but using the specified range for the random values.
pub fn ranvv(&self,d:usize,n:usize) -> Result<Rvv,RE>
Rvv value is a wrapped Vec<Vec<_>>
consisting of n vectors, each of length d, filled with random numbers of one of the main primitive types. Note that only the whole result is wrapped, not each individual vector or element of it. Thus, again, only one pattern extraction is needed.
pub fn ranvv_in(&self,d:usize,n:usize,min:f64,max:f64) -> Result<Rvv,RE>
same as ranvv
but using the specified range for the random values.
There is no need to read beyond this point for normal daily use of this crate. However, there may be special circumstances, when using directly one of the typed functions is more convenient. Such as when needing only one specific end type. Another circumstance may be when wanting to use specific random number generator(s), different to the default ones used within the above methods. (Several are provided).
Utility functions to directly generate vectors of random numbers of common numeric end types:
/// Generates vector of size d,
/// filled with full range u64 random numbers.
pub fn ranvu64(d: usize) -> Result<Vec<u64>,RE>
/// Generates vector of size d, of full range i64 random numbers.
pub fn ranvi64(d: usize) -> Result<Vec<i64>,RE>
/// Generates vector of size d, i64 random numbers in [min,max].
pub fn ranvi64_in(d: usize, min:i64, max:i64) -> Result<Vec<i64>,RE> {
/// Generates vector of size d, of f64 random numbers in [0,1).
pub fn ranvf64(d: usize) -> Result<Vec<f64>,RE>
/// Generates vector of size d, of u16 random numbers in [0,65535].
pub fn ranvu16(d: usize) -> Result<Vec<u16>,RE>
/// Generates vector of size d, of u8 random numbers in [0,255].
pub fn ranvu8(d: usize) -> Result<Vec<u8>,RE>
Utility functions to generate vectors of vectors (matrices) of random numbers of common numeric end types:
/// Generates n vectors of size d each,
/// filled with full range u64 random numbers.
pub fn ranvvu64(d: usize, n: usize) -> Result<Vec<Vec<u64>>,RE>
/// Generates n vectors of size d each, of full range i64 random numbers.
pub fn ranvvi64(d: usize, n: usize) -> Result<Vec<Vec<i64>>,RE>
/// Generates n vectors of size d, each of i64 random numbers in [min,max].
pub fn ranvvi64_in(d: usize, n: usize, min:i64, max:i64) -> Result<Vec<Vec<i64>>,RE>
/// Generates n vectors of size d each, of f64 random numbers in [0,1).
pub fn ranvvf64(d: usize, n: usize) -> Result<Vec<Vec<f64>>,RE>
/// Generates n vectors of size d each, of u8 random numbers in [0,255].
pub fn ranvvu16(d: usize, n: usize) -> Result<Vec<Vec<u16>>,RE>
/// Generates n vectors of size d each, of u8 random numbers in [0,255].
pub fn ranvvu8(d: usize, n: usize) -> Result<Vec<Vec<u8>>,RE>
And these f64 alternatives, using the improved f64 generator xoshif64()
:
/// Generates vector of size d, of f64 random numbers in [0,1).
/// Bit slower but otherwise superior to plain `ranvf64`.
pub fn ranvf64_xoshi(d: usize) -> Result<Vec<f64>,RE>
/// Generates n vectors of size d each, of f64 random numbers in [0,1).
pub fn ranvvf64_xoshi(d: usize, n: usize) -> Result<Vec<Vec<f64>>,RE>
xoshiu64()
generates u64 random numbers in full 64 bit range and 2^256 state space. That means the sequence is not going to repeat for a very long time. This algorithm is used to construct random numbers of all (unsigned) integer types and ranges up to 64 bits.
splitmix()
also generates u64 numbers. It is used here only to generate the initial seeds for the 'xoshi' type algorithms.
Some transformation wrappers for xoshiu64()
:
/// Get random numbers of various smaller unsigned integer
/// types, by specifying the number of bits required,
/// e.g. `ran_ubits(16) as u16`
pub fn ran_ubits(bits:u8) -> u64
/// Generate u64 random number in the interval [min,max].
pub fn ran_urange(min:u64, max:u64) -> u64
/// Generate i64 random number in the interval [min,max].
pub fn ran_irange(min:i64, max:i64) -> i64
ranf64()
is a little older (George Marsaglia, 2003). It has been adapted here to generate f64 numbers in the standard range: half open interval [0,1). That means its output can be easily transformed into any other range. Its main claim to fame is its superior speed.
xoshif64()
is also fast, though not quite as much as ranf64()
but it makes up for it by quality. It has also been adapted to output f64 numbers in the standard range [0,1).
There is also a function that transforms any f64 number in standard range [0,1) to a new range:
/// Transform f64 number in [0,1) to [min,max)
pub fn ran_ftrans(rnum:f64, min:f64, max:f64) -> f64
Version 1.0.4 Replaced all panics by more thorough error checking and custom errors.
Version 1.0.3 Updated the dev dependency.
Version 1.0.2 Fixed dimension error in ranvv_in
. Updated dev-depency from devtimer
to times
. Added a timing test.
Version 1.0.1 Added generic get functions to unpack the data but note that they will only work if all the From
converters have been fully implemented. get_generic
upacks Rnum type, getv_generic
unpacks Rv type and getvv_generic
unpacks Rvv type.
Version 1.0.0 No substantive changes for a while, upgrading to Version 1.0.0.
Author: liborty
Source Code: https://github.com/liborty/random
License: BSD-3-Clause license
1625013180
There are two types of random number generators: pseudo-random number generator and true random number generator.
Pseudorandom numbers depend on computer algorithms. The computer uses algorithms to generate random numbers. These random numbers are not truly random because they are predictable like the generated numbers using NumPy random seed.
Whereas, truly random numbers are generated by measuring truly physical random parameters so we can ensure that the generated numbers are truly random.
The pseudo-random numbers are not safe to use in cryptography because they can be guessed by attackers.
In Python, the built-in random module generates pseudo-random numbers. In this tutorial, we will discuss both types. So let’s get started.
Table of Contents
#python #random #generate random numbers #random numbers #generate random numbers in python
1643176207
Serde
*Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.*
You may be looking for:
#[derive(Serialize, Deserialize)]
Click to show Cargo.toml. Run this code in the playground.
[dependencies]
# The core APIs, including the Serialize and Deserialize traits. Always
# required when using Serde. The "derive" feature is only required when
# using #[derive(Serialize, Deserialize)] to make Serde work with structs
# and enums defined in your crate.
serde = { version = "1.0", features = ["derive"] }
# Each data format lives in its own crate; the sample code below uses JSON
# but you may be using a different one.
serde_json = "1.0"
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let point = Point { x: 1, y: 2 };
// Convert the Point to a JSON string.
let serialized = serde_json::to_string(&point).unwrap();
// Prints serialized = {"x":1,"y":2}
println!("serialized = {}", serialized);
// Convert the JSON string back to a Point.
let deserialized: Point = serde_json::from_str(&serialized).unwrap();
// Prints deserialized = Point { x: 1, y: 2 }
println!("deserialized = {:?}", deserialized);
}
Serde is one of the most widely used Rust libraries so any place that Rustaceans congregate will be able to help you out. For chat, consider trying the #rust-questions or #rust-beginners channels of the unofficial community Discord (invite: https://discord.gg/rust-lang-community), the #rust-usage or #beginners channels of the official Rust Project Discord (invite: https://discord.gg/rust-lang), or the #general stream in Zulip. For asynchronous, consider the [rust] tag on StackOverflow, the /r/rust subreddit which has a pinned weekly easy questions post, or the Rust Discourse forum. It's acceptable to file a support issue in this repo but they tend not to get as many eyes as any of the above and may get closed without a response after some time.
Download Details:
Author: serde-rs
Source Code: https://github.com/serde-rs/serde
License: View license
1619614811
Random Password Generator is a program that automatically generates a password randomly. Those generated passwords are mix with numbers, alphabets, symbols, and punctuations. This type of program helps the user to create a strong password.
Step By Step Tutorial :https://cutt.ly/ZbiDeyL
#password generator #random password generator #python password generator #random password generator javascript #html #javascript
1665500100
The rationale for this crate is to generate good quality random numbers fast, simply and with a minimal footprint.
Not everyone wants to add 375 kB, plus another ten dependencies, just to generate a bunch of random numbers for testing ( looking at the 'other' crate: rand
).
In contradistinction, this crate is lightweight and it has no dependencies.
Even so, there are four different algorithms on offer, plus a good range of utility functions to easily generate individual numbers of various types, vectors, and vectors of vectors filled with random numbers.
The main objective has been the ease of use rather than flat-out speed but the algorithms are neverheless very fast.
It is highly recommended to read and run tests/tests.rs
with examples of usage.
use ran::*; or
use ran::{set_seeds,RE,Rnum,Rv,Rvv};
These algorithms use thread safe static seeds. It is strongly recommended to initialise them with set_seeds(value);
in every thread where you may want to be generating random numbers, otherwise you will get the same sequence every time, based on the default value. Any u64 value will do to initiate a new, different, random sequence. Of course, the same seed will always produce the same sequence and this is sometimes actually useful for exact testing comparisons.
/// This function initialises SEED and xoshi seeds X0-X3.
/// The supplied value must be non zero,
/// otherwise seeds will remain unchanged.
pub fn set_seeds( seed:u64 )
Simple instructive example to generate a dxn matrix of random bytes:
let matrix = Rnum::newu8().ranvv(d, n)?.getvvu8()?;
First we created Rnum instance for the required type (u8). This can be saved with let statement and reused for repeated generations of values, vectors and matrices of the same end type. Next we call on it generic method ranv(d,n)
, that generates random numbers. Finally, we retrieve the matrix from its wrapper with getvvu8()
. The last two methods must agree on the target object, in this case both indicate vv
= vec of vecs
. They both potentially return custom error RE
: here we are just passing it up with the ?
operator.
Polymorphic interface avoids having to use different typed functions for each primitive type. This can be too repetitive, given that there are quite a few primitive numeric types. Nevertheless, such typed functions are also available in (use ran::generators::*;
). They can be used in simple applications directly (see below, section Explicitly Typed Functions).
In lib.rs
we define three polymorphic (generic) enum types:
/// Wrapper for enum polymorphism - single value
pub enum Rnum {
F64(f64), U64(u64), I64(i64), U16(u16), U8(u8)
// Should be extended to cover all numeric types?
}
/// Wrapper for enum polymorphism - vectors
pub enum Rv {
F64(Vec<f64>), U64(Vec<u64>), I64(Vec<i64>), U16(Vec<u16>), U8(Vec<u8>)
}
/// Wrapper for enum polymorphism - vectors of vectors
pub enum Rvv {
F64(Vec<Vec<f64>>),
U64(Vec<Vec<u64>>),
I64(Vec<Vec<i64>>),
U16(Vec<Vec<i16>>),
U8(Vec<Vec<u8>>)
}
Their filling with random numbers of required types is done by their associated functions
, defined in module impls.rs
. First create an instance of one of these types. For single random numbers, it will be enum type Rnum
, of the variant corresponding to the end-type of the random numbers wanted.
Rnum, Rv, Rvv
are just wrapper enum types, serving to communicate to the generic method(s) information about the actual type of the (random) number(s) wanted. The following example shows how to create instance variables for all them:
let rf = Rnum::newf64();
let ru = Rnum::newu64();
let ri = Rnum::newi64();
let ru16 = Rnum::newu16();
let ru8 = Rnum::newu8();
We can then apply common generic method(s) to all such variables to generate the required random numbers. For example:
println!("Random numbers in specified ranges: {}, {}, {}, {}",
rf.rannum_in(0.,100.), // wrapped f64 value 0. to 100.
ru.rannum_in(1.,1000.), // wrapped u64, 1 to 1000 (inclusive)
ri.rannum_in(-10.,10.), // wrapped i64, -10 to 10 (inclusive)
ru16.rannum_in(60000.,65535.), // u16, 60000 to 65535
ru8.rannum_in(1.,6.) // wrapped u8, 1 to 6 (inclusive)
);
They all print because Display
has been implemented for these three enum types. Their inner wrapped values can be if let
pattern extracted as follows:
use anyhow::{Result,bail};
if let Rnum::F64(x) = rf { utilise the x:f64 value }
else { bail!("rf does not hold value of f64 type!") };
The else branch can be used to report disappointed type expectations, as shown (assuming here that anyhow
crate is being used for error handling). Alternatively, else
can be used to return some default value, e.g. {0_f64}
or it can be dismissed with a semicolon, using if let
as a statement, rather than as an expression. In this case, should this particular extraction attempt fail, it will be just ignored:
// wrapped vec of random u8 values
if let Rv::U8(vx) = ru8.ranv_in(20,1.,6.)?
{ println!("Dice roll sequence: {}", stringv(&vx)) };
This example illustrated the use of enum type Rv
, used for vector of random numbers. As can be seen, its variants are extracted in the same way as from Rnum
. (The helper function stringv
from module secondary.rs
converted the extracted vector to a String to facilitate its printing). Of course, Rv type object (unextracted) would print as it is.
There is also enum type Rvv
for returning vectors of vectors of random numbers:
// vec of vecs using ranvv_in(d,n,min,max) and Display of Rvv
println!(
"5x5 matrix of integers in range [-10,10]:\n{}",
ri.ranvv_in(5,5,-10.,10.)?
);
stringvv
is another utility function to enable display of generic vectors of vectors. We did not need to use it here since Dislay
is implemented for Rvv
type and we did not bother to extract the wrapped value (vector of vectors).
The results wrapped within all three return types: Rnum,Rv,Rvv
can all be pattern extracted as needed with if let
.
Alternatively, for convenience, they can all be extracted with supplied get
methods. Their names follow this syntax: get{|v|vv}end_type()
.
// the following line tests 'getvi64()'
let pairofints = ri.ranv(2)?.getvi64()?;
println!("2 random i64s: {}", stringv(&pairofints));
Initialisation: the Self produced is Rnum
type and will contain the default value zero of the required numeric end type.
pub fn newf64() -> Self
pub fn newu64() -> Self
pub fn newi64() -> Self
pub fn newu16() -> Self
pub fn newu8() -> Self
The following methods are all implemented for Rnum
, that means invoked on Rnum
type variable. Even when generating Rv
or Rvv
type results. Rnum
type input variable (self
) in all cases serves just to inform the generic method about the numeric type required for the generated values:
pub fn rannum(&self) -> Self
returns a wrapped random number of one of the main types in maximum range allowed by the width of the type. The standardised range [0,1) is used for f64
.
pub fn rannum_in(&self,min:f64,max:f64) -> Self
returns a wrapped random number of one of the main types in the range min,max (min,max are always f64
s for commonality). The range should not exceed the width of the type, e.g. 0.,255. for u8
. Nor should it be negative for unsigned types.
pub fn ranv(&self,d:usize) -> Result<Rv,RE>
Rv value is a wrapped Vec of length d filled with random numbers of one of the main primitive types. Note that the whole Vec
is wrapped, not each individual element of it. Thus only one pattern extraction is needed.
pub fn ranv_in(&self,d:usize,min:f64,max:f64) -> Rv
same as ranv
but using the specified range for the random values.
pub fn ranvv(&self,d:usize,n:usize) -> Result<Rvv,RE>
Rvv value is a wrapped Vec<Vec<_>>
consisting of n vectors, each of length d, filled with random numbers of one of the main primitive types. Note that only the whole result is wrapped, not each individual vector or element of it. Thus, again, only one pattern extraction is needed.
pub fn ranvv_in(&self,d:usize,n:usize,min:f64,max:f64) -> Result<Rvv,RE>
same as ranvv
but using the specified range for the random values.
There is no need to read beyond this point for normal daily use of this crate. However, there may be special circumstances, when using directly one of the typed functions is more convenient. Such as when needing only one specific end type. Another circumstance may be when wanting to use specific random number generator(s), different to the default ones used within the above methods. (Several are provided).
Utility functions to directly generate vectors of random numbers of common numeric end types:
/// Generates vector of size d,
/// filled with full range u64 random numbers.
pub fn ranvu64(d: usize) -> Result<Vec<u64>,RE>
/// Generates vector of size d, of full range i64 random numbers.
pub fn ranvi64(d: usize) -> Result<Vec<i64>,RE>
/// Generates vector of size d, i64 random numbers in [min,max].
pub fn ranvi64_in(d: usize, min:i64, max:i64) -> Result<Vec<i64>,RE> {
/// Generates vector of size d, of f64 random numbers in [0,1).
pub fn ranvf64(d: usize) -> Result<Vec<f64>,RE>
/// Generates vector of size d, of u16 random numbers in [0,65535].
pub fn ranvu16(d: usize) -> Result<Vec<u16>,RE>
/// Generates vector of size d, of u8 random numbers in [0,255].
pub fn ranvu8(d: usize) -> Result<Vec<u8>,RE>
Utility functions to generate vectors of vectors (matrices) of random numbers of common numeric end types:
/// Generates n vectors of size d each,
/// filled with full range u64 random numbers.
pub fn ranvvu64(d: usize, n: usize) -> Result<Vec<Vec<u64>>,RE>
/// Generates n vectors of size d each, of full range i64 random numbers.
pub fn ranvvi64(d: usize, n: usize) -> Result<Vec<Vec<i64>>,RE>
/// Generates n vectors of size d, each of i64 random numbers in [min,max].
pub fn ranvvi64_in(d: usize, n: usize, min:i64, max:i64) -> Result<Vec<Vec<i64>>,RE>
/// Generates n vectors of size d each, of f64 random numbers in [0,1).
pub fn ranvvf64(d: usize, n: usize) -> Result<Vec<Vec<f64>>,RE>
/// Generates n vectors of size d each, of u8 random numbers in [0,255].
pub fn ranvvu16(d: usize, n: usize) -> Result<Vec<Vec<u16>>,RE>
/// Generates n vectors of size d each, of u8 random numbers in [0,255].
pub fn ranvvu8(d: usize, n: usize) -> Result<Vec<Vec<u8>>,RE>
And these f64 alternatives, using the improved f64 generator xoshif64()
:
/// Generates vector of size d, of f64 random numbers in [0,1).
/// Bit slower but otherwise superior to plain `ranvf64`.
pub fn ranvf64_xoshi(d: usize) -> Result<Vec<f64>,RE>
/// Generates n vectors of size d each, of f64 random numbers in [0,1).
pub fn ranvvf64_xoshi(d: usize, n: usize) -> Result<Vec<Vec<f64>>,RE>
xoshiu64()
generates u64 random numbers in full 64 bit range and 2^256 state space. That means the sequence is not going to repeat for a very long time. This algorithm is used to construct random numbers of all (unsigned) integer types and ranges up to 64 bits.
splitmix()
also generates u64 numbers. It is used here only to generate the initial seeds for the 'xoshi' type algorithms.
Some transformation wrappers for xoshiu64()
:
/// Get random numbers of various smaller unsigned integer
/// types, by specifying the number of bits required,
/// e.g. `ran_ubits(16) as u16`
pub fn ran_ubits(bits:u8) -> u64
/// Generate u64 random number in the interval [min,max].
pub fn ran_urange(min:u64, max:u64) -> u64
/// Generate i64 random number in the interval [min,max].
pub fn ran_irange(min:i64, max:i64) -> i64
ranf64()
is a little older (George Marsaglia, 2003). It has been adapted here to generate f64 numbers in the standard range: half open interval [0,1). That means its output can be easily transformed into any other range. Its main claim to fame is its superior speed.
xoshif64()
is also fast, though not quite as much as ranf64()
but it makes up for it by quality. It has also been adapted to output f64 numbers in the standard range [0,1).
There is also a function that transforms any f64 number in standard range [0,1) to a new range:
/// Transform f64 number in [0,1) to [min,max)
pub fn ran_ftrans(rnum:f64, min:f64, max:f64) -> f64
Version 1.0.4 Replaced all panics by more thorough error checking and custom errors.
Version 1.0.3 Updated the dev dependency.
Version 1.0.2 Fixed dimension error in ranvv_in
. Updated dev-depency from devtimer
to times
. Added a timing test.
Version 1.0.1 Added generic get functions to unpack the data but note that they will only work if all the From
converters have been fully implemented. get_generic
upacks Rnum type, getv_generic
unpacks Rv type and getvv_generic
unpacks Rvv type.
Version 1.0.0 No substantive changes for a while, upgrading to Version 1.0.0.
Author: liborty
Source Code: https://github.com/liborty/random
License: BSD-3-Clause license
1620992479
In this digital world, online businesses aspire to catch the attention of users in a modern and smarter way. To achieve it, they need to traverse through new approaches. Here comes to spotlight is the user-generated content or UGC.
What is user-generated content?
“ It is the content by users for users.”
Generally, the UGC is the unbiased content created and published by the brand users, social media followers, fans, and influencers that highlight their experiences with the products or services. User-generated content has superseded other marketing trends and fallen into the advertising feeds of brands. Today, more than 86 percent of companies use user-generated content as part of their marketing strategy.
In this article, we have explained the ten best ideas to create wonderful user-generated content for your brand. Let’s start without any further ado.
Generally, social media platforms help the brand to generate content for your users. Any user content that promotes your brand on the social media platform is the user-generated content for your business. When users create and share content on social media, they get 28% higher engagement than a standard company post.
Furthermore, you can embed your social media feed on your website also. you can use the Social Stream Designer WordPress plugin that will integrate various social media feeds from different social media platforms like Facebook, Twitter, Instagram, and many more. With this plugin, you can create a responsive wall on your WordPress website or blog in a few minutes. In addition to this, the plugin also provides more than 40 customization options to make your social stream feeds more attractive.
In general, surveys can be used to figure out attitudes, reactions, to evaluate customer satisfaction, estimate their opinions about different problems. Another benefit of customer surveys is that collecting outcomes can be quick. Within a few minutes, you can design and load a customer feedback survey and send it to your customers for their response. From the customer survey data, you can find your strengths, weaknesses, and get the right way to improve them to gain more customers.
Additionally, it is the best way to convert your brand leads to valuable customers. The key to running a successful contest is to make sure that the reward is fair enough to motivate your participation. If the product is relevant to your participant, then chances are they were looking for it in the first place, and giving it to them for free just made you move forward ahead of your competitors. They will most likely purchase more if your product or service satisfies them.
Furthermore, running contests also improve the customer-brand relationship and allows more people to participate in it. It will drive a real result for your online business. If your WordPress website has Google Analytics, then track contest page visits, referral traffic, other website traffic, and many more.
The business reviews help your consumers to make a buying decision without any hurdle. While you may decide to remove all the negative reviews about your business, those are still valuable user-generated content that provides honest opinions from real users. Customer feedback can help you with what needs to be improved with your products or services. This thing is not only beneficial to the next customer but your business as a whole.
Reviews are powerful as the platform they are built upon. That is the reason it is important to gather reviews from third-party review websites like Google review, Facebook review, and many more, or direct reviews on a website. It is the most vital form of feedback that can help brands grow globally and motivate audience interactions.
However, you can also invite your customers to share their unique or successful testimonials. It is a great way to display your products while inspiring others to purchase from your website.
Moreover, Instagram videos create around 3x more comments rather than Instagram photo posts. Instagram videos generally include short videos posted by real customers on Instagram with the tag of a particular brand. Brands can repost the stories as user-generated content to engage more audiences and create valid promotions on social media.
Similarly, imagine you are browsing a YouTube channel, and you look at a brand being supported by some authentic customers through a small video. So, it will catch your attention. With the videos, they can tell you about the branded products, especially the unboxing videos displaying all the inside products and how well it works for them. That type of video is enough to create a sense of desire in the consumers.
#how to get more user generated content #importance of user generated content #user generated content #user generated content advantages #user generated content best practices #user generated content pros and cons