Click here to Skip to main content
15,892,253 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Color spectrum representation Pin
Luc Pattyn21-Aug-07 11:55
sitebuilderLuc Pattyn21-Aug-07 11:55 
AnswerRe: Color spectrum representation Pin
El Corazon21-Aug-07 13:58
El Corazon21-Aug-07 13:58 
AnswerRe: Color spectrum representation Pin
Russell'22-Aug-07 5:48
Russell'22-Aug-07 5:48 
QuestionSelective randomization Pin
Kevnar20-Aug-07 21:47
Kevnar20-Aug-07 21:47 
AnswerRe: Selective randomization Pin
cp987620-Aug-07 22:01
cp987620-Aug-07 22:01 
AnswerRe: Selective randomization [modified] Pin
Kevnar20-Aug-07 22:15
Kevnar20-Aug-07 22:15 
GeneralRe: Selective randomization Pin
Kevnar30-Aug-07 6:39
Kevnar30-Aug-07 6:39 
AnswerRe: Selective randomization Pin
Luc Pattyn20-Aug-07 23:08
sitebuilderLuc Pattyn20-Aug-07 23:08 
Hi,


if you want an integer number j in the range [min, max) where each possible
value j has a different probability, you could:
- define an array P[j] that holds the relative probability (we use integers,
i.e. the absolute probability multiplied by N, the sum of all P[j])
- use a random number generator to obtain a number k in the range [0, N)
- find the value of j for which SUM(P(j)<=k<sum(p(j+1))
where="" sum="" is="" taken="" over="" [min,="" j).

btw:="" the="" notation="" [a,b)="" means="" range="" from="" a="" up="" to="" b,="" including="" a,="" excluding="" b.

the="" final="" transformation="" k--="">j can be speeded up by:
- storing SUM(P(j)) for all j
- and even, if N is not too large, using an array of size N


Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]


this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google


GeneralRe: Selective randomization Pin
cp987621-Aug-07 0:55
cp987621-Aug-07 0:55 
GeneralRe: Selective randomization Pin
Luc Pattyn21-Aug-07 1:33
sitebuilderLuc Pattyn21-Aug-07 1:33 
GeneralRe: Selective randomization Pin
Luc Pattyn21-Aug-07 1:39
sitebuilderLuc Pattyn21-Aug-07 1:39 
GeneralRe: Selective randomization Pin
Kevnar21-Aug-07 8:26
Kevnar21-Aug-07 8:26 
GeneralRe: Selective randomization Pin
cp987621-Aug-07 13:47
cp987621-Aug-07 13:47 
Question2D random generator Pin
vlasto7715-Aug-07 23:02
vlasto7715-Aug-07 23:02 
AnswerRe: 2D random generator Pin
cp987616-Aug-07 0:15
cp987616-Aug-07 0:15 
AnswerRe: 2D random generator Pin
El Corazon16-Aug-07 3:54
El Corazon16-Aug-07 3:54 
AnswerRe: 2D random generator Pin
yoaz18-Aug-07 9:12
yoaz18-Aug-07 9:12 
AnswerRe: 2D random generator Pin
Russell'19-Aug-07 3:07
Russell'19-Aug-07 3:07 
QuestionColour Shades ( Quick...before Luc / CPallini answers.) Pin
Malcolm Smart15-Aug-07 2:24
Malcolm Smart15-Aug-07 2:24 
AnswerRe: Colour Shades ( Quick...before Luc / CPallini answers.) Pin
IdUnknown15-Aug-07 4:29
IdUnknown15-Aug-07 4:29 
AnswerRe: Colour Shades ( Quick...before Luc / CPallini answers.) Pin
Luc Pattyn15-Aug-07 4:42
sitebuilderLuc Pattyn15-Aug-07 4:42 
GeneralRe: Colour Shades ( Quick...before Luc / CPallini answers.) Pin
mabo4216-Aug-07 0:59
mabo4216-Aug-07 0:59 
GeneralRe: Colour Shades ( Quick...before Luc / CPallini answers.) Pin
Luc Pattyn16-Aug-07 1:02
sitebuilderLuc Pattyn16-Aug-07 1:02 
GeneralRe: Colour Shades ( Quick...before Luc / CPallini answers.) Pin
mabo4216-Aug-07 1:16
mabo4216-Aug-07 1:16 
NewsThe origins of calculus Pin
73Zeppelin14-Aug-07 12:49
73Zeppelin14-Aug-07 12:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.