Skip to content

Instantly share code, notes, and snippets.

@tonmcg
Created March 20, 2018 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tonmcg/07935da317fdaf9581c9cb7ec4c4292f to your computer and use it in GitHub Desktop.
Save tonmcg/07935da317fdaf9581c9cb7ec4c4292f to your computer and use it in GitHub Desktop.
M Language Data Processing Functions
let
List.RandomSelection = (sourceList as list) as text =>
let
Selection = sourceList{Number.RoundDown(Number.RandomBetween(0, List.Count(sourceList)))}
in
Selection,
DefineDocs = [
Documentation.Name = " List.RandomSelection",
Documentation.Description = " Randomly select a value from a list.",
Documentation.LongDescription = " Randomly select a value from a list. The sourceList provides a list of values, either numerical or character.",
Documentation.Category = " List.Transform",
Documentation.Source = " ",
Documentation.Author = " Tony McGovern: www.emdata.ai",
Documentation.Examples = {
[
Description = "Randomly select a value from a list of countries.",
Code = " RandomSelection({""Portugal"", ""United Kingdom"", ""Germany"", ""New Zealand"", ""Australia"", ""Belgium"", ""France""}",
Result = "Germany"
]
}
]
in
Value.ReplaceType(
List.RandomSelection,
Value.ReplaceMetadata(
Value.Type(List.RandomSelection),
DefineDocs
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment