• R/O
  • SSH

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision154d30e4eb43633f94bbb37a642e4e3e6a5f6f3a (tree)
Time2024-10-06 02:51:59
AuthorLorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

I added a function to generate random numbers with a given sum.

Change Summary

Incremental Difference

diff -r a52506589994 -r 154d30e4eb43 R-codes/stat_lib.R
--- a/R-codes/stat_lib.R Fri Oct 04 17:43:49 2024 +0200
+++ b/R-codes/stat_lib.R Sat Oct 05 19:51:59 2024 +0200
@@ -7667,3 +7667,21 @@
76677667
76687668 return(result)
76697669 }
7670+
7671+
7672+
7673+## function to generate n positive real number whose sum is a given total
7674+
7675+random_sum <- function(total, n){
7676+
7677+ ss <- runif(n+1, 0, 1) |>
7678+ scale01() |>
7679+ multiply_by(total) |>
7680+ sort()
7681+
7682+ res <- diff(ss)
7683+
7684+ return(res)
7685+
7686+
7687+}