Click here to Skip to main content
15,848,483 members
Home / Discussions / C#
   

C#

 
AnswerRe: Multiple sliders or trackbars Pin
ZurdoDev9-Feb-18 10:10
professionalZurdoDev9-Feb-18 10:10 
AnswerRe: Multiple sliders or trackbars Pin
BillWoodruff11-Feb-18 0:23
professionalBillWoodruff11-Feb-18 0:23 
GeneralRe: Multiple sliders or trackbars Pin
Member 1367044211-Feb-18 13:59
Member 1367044211-Feb-18 13:59 
GeneralRe: Multiple sliders or trackbars Pin
BillWoodruff11-Feb-18 17:56
professionalBillWoodruff11-Feb-18 17:56 
GeneralRe: Multiple sliders or trackbars Pin
Member 1367028512-Feb-18 1:54
Member 1367028512-Feb-18 1:54 
QuestionHow to add a discrete transfer function in C# code? Pin
Member 136703089-Feb-18 6:21
Member 136703089-Feb-18 6:21 
AnswerRe: How to add a discrete transfer function in C# code? Pin
OriginalGriff9-Feb-18 6:27
mveOriginalGriff9-Feb-18 6:27 
Questiongetting same numbers when executing a random number generation method? Pin
auting828-Feb-18 7:47
auting828-Feb-18 7:47 
I am making a DAQ-Simulator that shall simulate generation of analog (0-1V) and digital 1 or 0 signals.
When I call my method sampling () and display the sensor data in my textbox, I always get the same numbers for my Analog sensors. Since this is a Random generation it should have been different numbers every time I click on Sample button Sigh | :sigh:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

<pre lang="c#">namespace DAQ_Simulator
{
    public partial class Form1 : Form
    {

        int counter;
        
        int maxSid = 10; //Number of sensors 7analog and 3 digital
        int maxAI, maxDI;
        // string sensor_values;
        string sTxt;
        
        private DateTime datetime;
        // Create an array of 10 sensor objects
          Sensor[] sObj = new Sensor[10];
        

        public Form1()
        {
            InitializeComponent();
        }
        private void displaySensorData(object sender, EventArgs e)
        {     
        }
        private void groupSampl_Enter(object sender, EventArgs e)
        {

        }
        private void textSampling_TextChanged(object sender, EventArgs e)
        {
            


        }
        private void btnSampling_Click(object sender, EventArgs e)
        {                  
                sampling();     
        }

        private void groupLogg_Enter(object sender, EventArgs e)
        {

        }

        private void txtLogging_TextChanged(object sender, EventArgs e)
        {

        }
        private void labelLoggingText_Click(object sender, EventArgs e)
        {

        }
        private void btnLogging_Click(object sender, EventArgs e)
        {
            
        }
        private void labelSensorValues_Click(object sender, EventArgs e)
        {

        }
        private void textSensorValues_TextChanged(object sender, EventArgs e)
        {
           
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
           
        }
        private void sampling()
        {
           

            for (counter = 0; counter < maxSid; counter++)
            {               
                sObj[counter] = new Sensor(counter);              
            }
            
            for (counter = 0; counter < maxSid; counter++)
            {
                for (counter = 0; counter < 10; counter++)
                {
                    sObj[counter] = new Sensor(counter);
                }
                // Get the object values as a string
                for (counter = 0; counter < maxSid; counter++)
                {
                    sTxt += sObj[counter].GetAnalogValue().ToString("F3");
                    textSensorValues.Text = sTxt;
                }                            
                textSensorValues.Text=sTxt;
            }
           
        }
    }
}


This is my Sensor class where I call the GetAnalogValue() from:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAQ_Simulator
{
    public class Sensor
    {
        double dVal;
        bool bVal;
        int sId;
        Random rSensVal;

        public Sensor(int id)
        {
            sId = id;
            rSensVal = new Random(id);
            dVal = 0.0F;
        }
        
        public double GetAnalogValue()
        {
            dVal += rSensVal.NextDouble();
            return dVal;         
       }
       
        public int GetDigitalValue()
        {
            Random bVal = new Random(2);
            int digital = bVal.Next(2);
            return digital;

        }
        public int GetSensId()
        {
            return sId;
        }


modified 8-Feb-18 12:54pm.

AnswerRe: getting same numbers when executing a random number generation method? Pin
Richard Deeming8-Feb-18 8:41
mveRichard Deeming8-Feb-18 8:41 
AnswerRe: getting same numbers when executing a random number generation method? Pin
OriginalGriff8-Feb-18 9:03
mveOriginalGriff8-Feb-18 9:03 
GeneralRe: getting same numbers when executing a random number generation method? Pin
Richard Deeming8-Feb-18 10:23
mveRichard Deeming8-Feb-18 10:23 
QuestionGridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL Pin
Deden Suansyah7-Feb-18 22:41
Deden Suansyah7-Feb-18 22:41 
AnswerRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL Pin
Deden Suansyah7-Feb-18 22:49
Deden Suansyah7-Feb-18 22:49 
AnswerRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL Pin
Richard MacCutchan7-Feb-18 23:13
mveRichard MacCutchan7-Feb-18 23:13 
GeneralRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL Pin
Deden Suansyah8-Feb-18 0:04
Deden Suansyah8-Feb-18 0:04 
GeneralRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL Pin
Richard MacCutchan8-Feb-18 0:13
mveRichard MacCutchan8-Feb-18 0:13 
AnswerRe: Gridview C# Windows Application - Function in each cell column can automatically write words PASS and FAIL PinPopular
Eddy Vluggen8-Feb-18 2:18
professionalEddy Vluggen8-Feb-18 2:18 
QuestionHow can I enumerate through OU's for nodes and add them to an existing treeview root node? Pin
turbosupramk37-Feb-18 11:35
turbosupramk37-Feb-18 11:35 
AnswerRe: How can I enumerate through OU's for nodes and add them to an existing treeview root node? Pin
BillWoodruff7-Feb-18 17:53
professionalBillWoodruff7-Feb-18 17:53 
Question(beginner question) help with code for a project Pin
Member 136645666-Feb-18 12:14
Member 136645666-Feb-18 12:14 
AnswerRe: (beginner question) help with code for a project Pin
Eddy Vluggen6-Feb-18 15:34
professionalEddy Vluggen6-Feb-18 15:34 
AnswerRe: (beginner question) help with code for a project Pin
Richard MacCutchan7-Feb-18 0:18
mveRichard MacCutchan7-Feb-18 0:18 
GeneralRe: (beginner question) help with code for a project Pin
Member 136645667-Feb-18 4:21
Member 136645667-Feb-18 4:21 
GeneralRe: (beginner question) help with code for a project Pin
Richard MacCutchan7-Feb-18 4:31
mveRichard MacCutchan7-Feb-18 4:31 
GeneralRe: (beginner question) help with code for a project Pin
Member 136645667-Feb-18 6:00
Member 136645667-Feb-18 6:00 

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.