Click here to Skip to main content
15,913,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help on Copy/Paste for DateTimePicker Pin
Gerry Schmitz16-Feb-18 5:30
mveGerry Schmitz16-Feb-18 5:30 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 318-Feb-18 22:05
manju 318-Feb-18 22:05 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 318-Feb-18 23:21
manju 318-Feb-18 23:21 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
Gerry Schmitz19-Feb-18 6:20
mveGerry Schmitz19-Feb-18 6:20 
GeneralRe: Help on Copy/Paste for DateTimePicker Pin
manju 319-Feb-18 20:43
manju 319-Feb-18 20:43 
QuestionUK buddy's needed with C# skill for mega big project Pin
stopthespying15-Feb-18 5:49
stopthespying15-Feb-18 5:49 
AnswerRe: UK buddy's needed with C# skill for mega big project Pin
OriginalGriff15-Feb-18 5:51
mveOriginalGriff15-Feb-18 5:51 
GeneralRe: UK buddy's needed with C# skill for mega big project Pin
stopthespying15-Feb-18 6:43
stopthespying15-Feb-18 6:43 
QuestionRe: UK buddy's needed with C# skill for mega big project Pin
Eddy Vluggen15-Feb-18 6:22
professionalEddy Vluggen15-Feb-18 6:22 
AnswerRe: UK buddy's needed with C# skill for mega big project Pin
stopthespying15-Feb-18 7:40
stopthespying15-Feb-18 7:40 
GeneralRe: UK buddy's needed with C# skill for mega big project Pin
Eddy Vluggen15-Feb-18 12:40
professionalEddy Vluggen15-Feb-18 12:40 
QuestionC# 2008 express building a query Pin
Member 330187815-Feb-18 4:01
Member 330187815-Feb-18 4:01 
AnswerRe: C# 2008 express building a query Pin
OriginalGriff15-Feb-18 5:01
mveOriginalGriff15-Feb-18 5:01 
AnswerRe: C# 2008 express building a query Pin
stopthespying15-Feb-18 6:48
stopthespying15-Feb-18 6:48 
QuestionImplementing a moving average Pin
auting8214-Feb-18 10:12
auting8214-Feb-18 10:12 
AnswerRe: Implementing a moving average Pin
OriginalGriff14-Feb-18 20:41
mveOriginalGriff14-Feb-18 20:41 
For starters, don't use two Random instances:
rSensVal = new Random(id);
digSensVal = new Random(id);
Because they are initialized with the same value, they will have the same sequence - use a single instance (or better a single static instance) and you will get a "more random" set of values. You might want to consider using the parameterless version of the constructor, which uses the system clock as the seed value so it gives a different sequence each time your app runs.

For a moving average, just add an array of values the same size as the group, an index, and a count. This will become a basic queue.
So for five values, you would have five elements:
C#
private double[] samples = new double[5];
private int index = 0;
private int count = 0;
Then its just a case of a simple method:
private double GetMovingAverage(double newValue)
    {
    // Insert
    if (count != samples.Length) count++;
    samples[index++] = newValue;
    if (index == samples.Length) index = 0;
    // Get average
    double sum = 0.0;
    for (int i = 0; i < count; i++)
        {
        sum += samples[i];
        }
    return sum / (double) (count);
    }
And you are done.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Implementing a moving average Pin
auting8214-Feb-18 23:54
auting8214-Feb-18 23:54 
AnswerRe: Implementing a moving average Pin
Ralf Meier15-Feb-18 0:25
mveRalf Meier15-Feb-18 0:25 
GeneralRe: Implementing a moving average Pin
Rob Philpott15-Feb-18 0:24
Rob Philpott15-Feb-18 0:24 
GeneralRe: Implementing a moving average Pin
OriginalGriff15-Feb-18 0:34
mveOriginalGriff15-Feb-18 0:34 
GeneralRe: Implementing a moving average Pin
auting8215-Feb-18 1:38
auting8215-Feb-18 1:38 
GeneralRe: Implementing a moving average Pin
OriginalGriff15-Feb-18 1:53
mveOriginalGriff15-Feb-18 1:53 
GeneralRe: Implementing a moving average Pin
auting8215-Feb-18 4:35
auting8215-Feb-18 4:35 
GeneralRe: Implementing a moving average Pin
OriginalGriff15-Feb-18 4:53
mveOriginalGriff15-Feb-18 4:53 
AnswerRe: Implementing a moving average Pin
Ralf Meier15-Feb-18 21:27
mveRalf Meier15-Feb-18 21:27 

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.